Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changelog #82

Merged
merged 2 commits into from Apr 14, 2013
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 76 additions & 0 deletions src/main/java/org/terasologylauncher/changelog/Changelog.java
@@ -0,0 +1,76 @@
/*
* Copyright (c) 2013 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.terasologylauncher.changelog;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.terasologylauncher.BuildType;
import org.w3c.dom.Document;
import org.xml.sax.SAXException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.net.URL;

/**
* @author MrBarsack
*/

public class Changelog {

private static final Logger logger = LoggerFactory.getLogger(Changelog.class);

private final BuildType buildType;

private final String NIGHTLY_URL = "http://jenkins.movingblocks.net/job/Terasology/";
private final String STABLE_URL = "http://jenkins.movingblocks.net/job/TerasologyStable/";

private final String WRAPPER = "/api/xml?xpath=//changeSet/item/msg[1]|//changeSet/item/author[1]/fullName&wrapper=msgs";


public Changelog(BuildType buildType) {
this.buildType = buildType;
}

public Document getChangelog(int version) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;

logger.debug("Changelog: " + buildType + " " + version);

try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
try {
if (buildType == BuildType.NIGHTLY) {
return builder.parse(new URL(NIGHTLY_URL + version + WRAPPER).openStream());
} else {
return builder.parse(new URL(STABLE_URL + version + WRAPPER).openStream());
}
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
logger.error("Error while loading changelog.");
return null;
}
}
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2013 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.terasologylauncher.changelog;

import org.w3c.dom.Document;
import org.w3c.dom.NodeList;

/**
* @author MrBarsack
*/

public class ChangelogBuilder {


public String getChangelog(Document changelog, int build) {
NodeList nodeList = null;

if (changelog != null) {
nodeList = changelog.getElementsByTagName("msg");
}

StringBuilder str = new StringBuilder("<b> Build:");

str.append(build).append("</b> <br/>");

assert nodeList != null;

for (int a = 0; a < nodeList.getLength(); a++) {
str.append('-').append(nodeList.item(a).getLastChild().getTextContent()).append("<br/>");
}
str.append("<br/>");

return str.toString();
}
}
29 changes: 15 additions & 14 deletions src/main/java/org/terasologylauncher/gui/LauncherFrame.java
Expand Up @@ -18,6 +18,8 @@

import org.terasologylauncher.BuildType;
import org.terasologylauncher.Settings;
import org.terasologylauncher.changelog.Changelog;
import org.terasologylauncher.changelog.ChangelogBuilder;
import org.terasologylauncher.launcher.TerasologyStarter;
import org.terasologylauncher.updater.GameData;
import org.terasologylauncher.updater.GameDownloader;
Expand All @@ -26,6 +28,7 @@
import org.terasologylauncher.util.OperatingSystem;
import org.terasologylauncher.version.TerasologyGameVersion;
import org.terasologylauncher.version.TerasologyLauncherVersionInfo;
import org.w3c.dom.Document;

import javax.swing.BorderFactory;
import javax.swing.JButton;
Expand Down Expand Up @@ -162,23 +165,15 @@ private void initComponents() {
infoTextPane.setEnabled(false);
infoTextPane.setHighlighter(null);
infoTextPane.setOpaque(false);
infoTextPane.setContentType("text/html");

infoTextPane.setForeground(Color.WHITE);

// TODO BundleUtils
infoTextPane.setText("Lorem ipsum dolor sit amet, \n " +
"consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore " +
"\n magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores " +
"\n et ea rebum. " +
"\n Stet clita kasd gubergren, " +
"\n no sea takimata sanctus est Lorem ipsum dolor sit amet. " +
"\n Lorem ipsum dolor " +
"sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore " +
"\n \n \n magna aliquyam erat, sed diam voluptua. " +
"\n At vero eos et accusam et justo duo dolores et ea rebum. " +
"\n Stet clita kasd gubergren, " +
"\n no sea takimata sanctus est " +
"\n Lorem ipsum dolor sit amet.");
Changelog changelog = new Changelog(settings.getBuildType());
Document document = changelog.getChangelog(settings.getBuildVersion(settings.getBuildType()));
ChangelogBuilder builder = new ChangelogBuilder();

infoTextPane.setText(builder.getChangelog(document, settings.getBuildVersion(settings.getBuildType())));

//infoTextPane.setBounds(updatePanel.getX() + 8, updatePanel.getY() + 8, updatePanelWidth - 16,
// updatePanelHeight - 16);
Expand Down Expand Up @@ -348,6 +343,12 @@ private void updateLabels() {

settingsButton.setText(BundleUtils.getLabel("launcher_settings"));
cancelButton.setText(BundleUtils.getLabel("launcher_cancel"));

Changelog changelog = new Changelog(settings.getBuildType());
Document document = changelog.getChangelog(settings.getBuildVersion(settings.getBuildType()));
ChangelogBuilder builder = new ChangelogBuilder();

infoTextPane.setText(builder.getChangelog(document, settings.getBuildVersion(settings.getBuildType())));
}

/**
Expand Down