Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.number>UNKNOWN</project.build.number>
<project.bitly-access-token>bitly-access-token</project.bitly-access-token>
</properties>

<repositories>
Expand Down Expand Up @@ -69,6 +70,17 @@
<project.build.number>${env.BUILD_NUMBER}</project.build.number>
</properties>
</profile>
<profile>
<id>bitly</id>
<activation>
<property>
<name>env.BITLY_ACCESS_TOKEN</name>
</property>
</activation>
<properties>
<project.bitly-access-token>${env.BITLY_ACCESS_TOKEN}</project.bitly-access-token>
</properties>
</profile>
</profiles>

<build>
Expand All @@ -90,21 +102,44 @@
<version>1.4.1</version>
<executions>
<execution>
<id>replace-bitly-access-token</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<basedir>${project.build.sourceDirectory}</basedir>
<includes>
<include>com/onarandombox/MultiverseCore/utils/webpaste/BitlyURLShortener.java</include>
</includes>
<replacements>
<replacement>
<token>bitly-access-token</token>
<value>${project.bitly-access-token}</value>
</replacement>
</replacements>
</configuration>
</execution>
<execution>
<id>replace-maven-version-number</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<basedir>${project.build.directory}/classes</basedir>
<includes>
<include>plugin.yml</include>
</includes>
<replacements>
<replacement>
<token>maven-version-number</token>
<value>${project.version}-b${project.build.number}</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
<configuration>
<file>target/classes/plugin.yml</file>
<replacements>
<replacement>
<token>maven-version-number</token>
<value>${project.version}-b${project.build.number}</value>
</replacement>
</replacements>
</configuration>
</plugin>
<!-- Jar Plugin -->
<plugin>
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,13 @@ public Map<String, String> getDetailedVersionInfo() {
public void appendVersionInfo(String moreVersionInfo) {
this.versionInfoBuilder.append(moreVersionInfo);
}

/**
* Adds a file to to the detailed version-info currently saved in this event.
* @param filename The name of the file.
* @param text The file's content.
*/
public void putDetailedVersionInfo(String filename, String text) {
this.detailedVersionInfo.put(filename, text);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
package com.onarandombox.MultiverseCore.utils.webpaste;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.io.IOException;
import java.util.Map;

/**
* An {@link URLShortener} using {@code bit.ly}.
* A {@link URLShortener} using {@code bit.ly}. Requires an access token.
*/
public class BitlyURLShortener extends HttpAPIClient implements URLShortener {
private static final String GENERIC_BITLY_REQUEST_FORMAT = "https://api-ssl.bitly.com/v3/shorten?format=txt&apiKey=%s&login=%s&longUrl=%s";
class BitlyURLShortener extends URLShortener {
private static final String ACCESS_TOKEN = "Bearer bitly-access-token";
private static final String BITLY_POST_REQUEST = "https://api-ssl.bitly.com/v4/shorten";

BitlyURLShortener() {
super(BITLY_POST_REQUEST, ACCESS_TOKEN);
if (ACCESS_TOKEN.endsWith("access-token")) throw new UnsupportedOperationException();
}

// I think it's no problem that these are public
private static final String USERNAME = "multiverse2";
private static final String API_KEY = "R_9dbff4862a3bc0c4218a7d78cc10d0e0";
/**
* {@inheritDoc}
*/
@Override
String encodeData(String data) {
JSONObject json = new JSONObject();
json.put("domain", "j.mp");
json.put("long_url", data);
return json.toJSONString();
}

public BitlyURLShortener() {
super(String.format(GENERIC_BITLY_REQUEST_FORMAT, API_KEY, USERNAME, "%s"));
/**
* {@inheritDoc}
*/
@Override
String encodeData(Map<String, String> data) {
throw new UnsupportedOperationException();
}

/**
Expand All @@ -22,13 +44,11 @@ public BitlyURLShortener() {
@Override
public String shorten(String longUrl) {
try {
String result = this.exec(longUrl);
if (!result.startsWith("http://j.mp/")) // ... then it's failed :/
throw new IOException(result);
return result;
} catch (IOException e) {
String stringJSON = this.exec(encodeData(longUrl), ContentType.JSON);
return (String) ((JSONObject) new JSONParser().parse(stringJSON)).get("link");
} catch (IOException | ParseException e) {
e.printStackTrace();
return longUrl; // sorry ...
return longUrl;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package com.onarandombox.MultiverseCore.utils.webpaste;

import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
* Pastes to {@code gist.github.com}. Requires an access token with the {@code gist} scope.
*/
class GitHubPasteService extends PasteService {
private final boolean isPrivate;
// this access token must have the "gist" scope
private static final String ACCESS_TOKEN = "token github-access-token";
private static final String GITHUB_POST_REQUEST = "https://api.github.com/gists";

GitHubPasteService(boolean isPrivate) {
super(GITHUB_POST_REQUEST, ACCESS_TOKEN);
this.isPrivate = isPrivate;
if (ACCESS_TOKEN.endsWith("access-token")) throw new UnsupportedOperationException();
}

/**
* {@inheritDoc}
*/
@Override
String encodeData(String data) {
Map<String, String> mapData = new HashMap<String, String>();
mapData.put("multiverse.txt", data);
return this.encodeData(mapData);
}

/**
* {@inheritDoc}
*/
@Override
String encodeData(Map<String, String> files) {
JSONObject root = new JSONObject();
root.put("description", "Multiverse-Core Debug Info");
root.put("public", !this.isPrivate);
JSONObject fileList = new JSONObject();
for (Map.Entry<String, String> entry : files.entrySet()) {
JSONObject fileObject = new JSONObject();
fileObject.put("content", entry.getValue());
fileList.put(entry.getKey(), fileObject);
}

root.put("files", fileList);
return root.toJSONString();
}

/**
* {@inheritDoc}
*/
@Override
public String postData(String data) throws PasteFailedException {
try {
String stringJSON = this.exec(encodeData(data), ContentType.JSON);
return (String) ((JSONObject) new JSONParser().parse(stringJSON)).get("html_url");
} catch (IOException | ParseException e) {
throw new PasteFailedException(e);
}
}

/**
* {@inheritDoc}
*/
@Override
public String postData(Map<String, String> data) throws PasteFailedException {
try {
String stringJSON = this.exec(encodeData(data), ContentType.JSON);
return (String) ((JSONObject) new JSONParser().parse(stringJSON)).get("html_url");
} catch (IOException | ParseException e) {
throw new PasteFailedException(e);
}
}

/**
* {@inheritDoc}
*/
@Override
public boolean supportsMultiFile() {
return true;
}
}

This file was deleted.

Loading