Skip to content

Commit

Permalink
packs: reports added to the Problems window
Browse files Browse the repository at this point in the history
  • Loading branch information
ilg-ul committed Jul 16, 2014
1 parent c1aa0dd commit 3e0f656
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 14 deletions.
48 changes: 48 additions & 0 deletions ilg.gnuarmeclipse.packs/src/ilg/gnuarmeclipse/packs/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.console.MessageConsoleStream;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -365,4 +368,49 @@ public static void makeFolderReadOnlyRecursive(File folder) {
}
}

public static String reportError(String message) {

try {
IMarker marker = ResourcesPlugin.getWorkspace().getRoot()
.createMarker(IMarker.PROBLEM);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.LOCATION, "-");
} catch (CoreException e) {
System.out.println(message);
}

return message;
}

public static String reportWarning(String message) {

try {
IMarker marker = ResourcesPlugin.getWorkspace().getRoot()
.createMarker(IMarker.PROBLEM);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_WARNING);
marker.setAttribute(IMarker.LOCATION, "-");
} catch (CoreException e) {
System.out.println(message);
}

return message;
}

public static String reportInfo(String message) {

try {
IMarker marker = ResourcesPlugin.getWorkspace().getRoot()
.createMarker(IMarker.PROBLEM);
marker.setAttribute(IMarker.MESSAGE, message);
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO);
marker.setAttribute(IMarker.LOCATION, "-");
} catch (CoreException e) {
System.out.println(message);
}

return message;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ private IStatus myRun(IProgressMonitor monitor) {
workUnits++;

} else {
m_out.println("Repo type \"" + type + "\" not supported.");
m_out.println(Utils.reportWarning("Repo type \"" + type
+ "\" not supported."));
}
}

Expand Down Expand Up @@ -188,7 +189,7 @@ private IStatus myRun(IProgressMonitor monitor) {
// m_out.println("Error: " + e.toString());
} catch (Exception e) {
Activator.log(e);
m_out.println("Failed: " + e.toString());
m_out.println(Utils.reportError(e.toString()));
}

IStatus status;
Expand All @@ -207,8 +208,8 @@ private IStatus myRun(IProgressMonitor monitor) {
duration = 1;
}

m_out.println("Refresh packs job completed in " + (duration + 500)
/ 1000 + "s.");
m_out.println(Utils.reportInfo("Refresh packs completed in "
+ (duration + 500) / 1000 + "s."));

status = Status.OK_STATUS;
}
Expand All @@ -230,10 +231,9 @@ private void readCmsisIndex(String indexUrl, List<String[]> pdscList) {
return;

} catch (FileNotFoundException e) {
m_out.println("Failed: " + e.toString());
m_out.println(Utils.reportError("File not found: " + e.getMessage()));
} catch (Exception e) {
Activator.log(e);
m_out.println("Failed: " + e.toString());
m_out.println(Utils.reportError(e.toString()));
}

return;
Expand Down Expand Up @@ -294,6 +294,9 @@ private void aggregateCmsis(Map<String, Object> repo) {

// If local file does not exist, create it
Utils.copyFile(sourceUrl, cachedFile, m_out, null);

Utils.reportInfo("Pack " + pdscName + " v" + pdscVersion
+ " cached.");
}

if (cachedFile.exists()) {
Expand All @@ -302,12 +305,14 @@ private void aggregateCmsis(Map<String, Object> repo) {
parser.parsePdscContent(pdscName, pdscVersion, contentRoot);

} else {
m_out.println("Missing \"" + cachedFile + "\", ignored");
m_out.println(Utils.reportWarning("Missing \"" + cachedFile
+ "\", ignored"));
return;
}

} catch (Exception e) {
m_out.println("Failed with \"" + e.getMessage() + "\", ignored");
m_out.println(Utils.reportWarning("Failed with \""
+ e.getMessage() + "\", ignored"));
return;
}

Expand All @@ -330,7 +335,7 @@ private void aggregateCmsis(Map<String, Object> repo) {
m_out.println("File \"" + file.getPath() + "\" written.");

} catch (IOException e) {
m_out.println("Failed: " + e.toString());
m_out.println(Utils.reportError(e.toString()));
}
}
}
Expand All @@ -348,9 +353,11 @@ private void cacheXcdlContent(Map<String, Object> repo) {
m_monitor.worked(1);

} catch (MalformedURLException e) {
m_out.println("Failed: " + e.toString());
m_out.println(Utils.reportError(e.toString()));
} catch (FileNotFoundException e) {
m_out.println(Utils.reportError("File not found: " + e.getMessage()));
} catch (IOException e) {
m_out.println("Failed: " + e.toString());
m_out.println(Utils.reportError(e.toString()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected IStatus run(IProgressMonitor monitor) {
versionNode.setBooleanProperty(Property.INSTALLED, true);

} catch (IOException e) {
m_out.println("Error " + e);
m_out.println(Utils.reportError(e.toString()));
}
}

Expand Down Expand Up @@ -232,6 +232,8 @@ private void installPack(Node versionNode) throws IOException {
copyFile(packUrl, archiveFileDownload);

archiveFileDownload.renameTo(archiveFile);

Utils.reportInfo("Pack " + archiveName + " downloaded.");
} else {
m_monitor.worked((int) archiveFile.length());
}
Expand All @@ -252,6 +254,8 @@ private void installPack(Node versionNode) throws IOException {

Utils.makeFolderReadOnlyRecursive(destRelPath.toFile());

Utils.reportInfo("Pack " + archiveName + " installed.");

m_out.println("All files write protected.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ protected IStatus run(IProgressMonitor monitor) {
// Add it to the list for final notifications
removedPacksList.add(versionNode);

Utils.reportInfo("Pack " + packFullName + " removed.");

} catch (IOException e) {
m_out.println(e.getMessage());
m_out.println(Utils.reportError(e.getMessage()));
break;
}
}
Expand Down

0 comments on commit 3e0f656

Please sign in to comment.