Skip to content
Browse files

buildwrapper plugin

  • Loading branch information...
1 parent 19fe875 commit 49f15b4a1480aaa94e418e267ab624345781e51b @JPMoresmau committed Sep 9, 2011
View
7 net.sf.eclipsefp.haskell.buildwrapper/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
View
1 net.sf.eclipsefp.haskell.buildwrapper/.gitignore
@@ -0,0 +1 @@
+bin/
View
28 net.sf.eclipsefp.haskell.buildwrapper/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>net.sf.eclipsefp.haskell.buildwrapper</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
View
8 net.sf.eclipsefp.haskell.buildwrapper/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+#Fri Sep 09 14:26:03 CEST 2011
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5
View
16 net.sf.eclipsefp.haskell.buildwrapper/META-INF/MANIFEST.MF
@@ -0,0 +1,16 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %bundleName
+Bundle-SymbolicName: net.sf.eclipsefp.haskell.buildwrapper
+Bundle-Version: 2.1.1
+Bundle-Activator: net.sf.eclipsefp.haskell.buildwrapper.BuildWrapperPlugin
+Bundle-Vendor: %bundleVendor
+Bundle-Localization: plugin
+Require-Bundle: org.eclipse.ui,
+ org.eclipse.core.runtime,
+ net.sf.eclipsefp.haskell.util;bundle-version="2.1.1",
+ net.sf.eclipsefp.haskell.scion.client;bundle-version="2.1.1",
+ org.eclipse.core.resources;bundle-version="3.5.2"
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+Export-Package: net.sf.eclipsefp.haskell.buildwrapper
View
4 net.sf.eclipsefp.haskell.buildwrapper/build.properties
@@ -0,0 +1,4 @@
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .
View
3 net.sf.eclipsefp.haskell.buildwrapper/plugin.properties
@@ -0,0 +1,3 @@
+# bundle manifest
+bundleVendor = The EclipseFP Project
+bundleName = Haskell BuildWrapper Utilities
View
153 ...sf.eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/BWFacade.java
@@ -0,0 +1,153 @@
+package net.sf.eclipsefp.haskell.buildwrapper;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Writer;
+import java.util.LinkedList;
+
+import net.sf.eclipsefp.haskell.buildwrapper.util.BWText;
+import net.sf.eclipsefp.haskell.scion.types.BuildOptions;
+import net.sf.eclipsefp.haskell.util.PlatformUtil;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+public class BWFacade {
+ private static final String prefix="build-wrapper-json:";
+
+ private String bwPath;
+ private String tempFolder=".dist-buildwrapper";
+ private String cabalPath;
+ private String cabalFile;
+
+ private File workingDir;
+
+ private Writer outStream;
+
+ public synchronized void build(BuildOptions bo){
+ LinkedList<String> command=new LinkedList<String>();
+ command.add("build");
+ command.add("--output="+bo.isOutput());
+ JSONArray obj=run(command,ARRAY);
+ }
+
+ public synchronized void synchronize(){
+ LinkedList<String> command=new LinkedList<String>();
+ command.add("synchronize");
+ JSONArray files=run(command,ARRAY);
+ }
+
+
+ private <T> T run(LinkedList<String> args,JSONFactory<T> f){
+ args.addFirst(bwPath);
+ args.add("--tempfolder="+tempFolder);
+ args.add("--cabalpath="+cabalPath);
+ args.add("--cabalfile="+cabalFile);
+ ProcessBuilder pb=new ProcessBuilder();
+ pb.directory(workingDir);
+ pb.redirectErrorStream(true);
+ pb.command(args);
+ T obj=null;
+ try {
+ Process p=pb.start();
+ BufferedReader br=new BufferedReader(new InputStreamReader(p.getInputStream(),"UTF8"));
+ String l=br.readLine();
+ while (l!=null){
+ outStream.write(l);
+ outStream.write(PlatformUtil.NL);
+ outStream.flush();
+ if (l.startsWith(prefix)){
+ String jsons=l.substring(prefix.length()).trim();
+ try {
+ obj=f.fromJSON(jsons);
+ } catch (JSONException je){
+ BuildWrapperPlugin.logError(BWText.process_parse_error, je);
+ }
+ }
+ l=br.readLine();
+ }
+ } catch (IOException ioe){
+ BuildWrapperPlugin.logError(BWText.process_launch_error, ioe);
+ }
+ return obj;
+ }
+
+
+ public String getTempFolder() {
+ return tempFolder;
+ }
+
+
+ public void setTempFolder(String tempFolder) {
+ this.tempFolder = tempFolder;
+ }
+
+
+ public String getCabalPath() {
+ return cabalPath;
+ }
+
+
+ public void setCabalPath(String cabalPath) {
+ this.cabalPath = cabalPath;
+ }
+
+
+ public String getCabalFile() {
+ return cabalFile;
+ }
+
+
+ public void setCabalFile(String cabalFile) {
+ this.cabalFile = cabalFile;
+ }
+
+
+ public File getWorkingDir() {
+ return workingDir;
+ }
+
+
+ public void setWorkingDir(File workingDir) {
+ this.workingDir = workingDir;
+ }
+
+
+ public Writer getOutStream() {
+ return outStream;
+ }
+
+
+ public void setOutStream(Writer outStream) {
+ this.outStream = outStream;
+ }
+
+
+ public String getBwPath() {
+ return bwPath;
+ }
+
+
+ public void setBwPath(String bwPath) {
+ this.bwPath = bwPath;
+ }
+
+ private static interface JSONFactory<T>{
+ T fromJSON(String json) throws JSONException;
+ }
+
+ private static JSONFactory<JSONArray> ARRAY=new JSONFactory<JSONArray>() {
+ public JSONArray fromJSON(String json)throws JSONException {
+ return new JSONArray(json);
+ }
+ };
+
+ private static JSONFactory<JSONObject> OBJECT=new JSONFactory<JSONObject>() {
+ public JSONObject fromJSON(String json)throws JSONException {
+ return new JSONObject(json);
+ }
+ };
+}
View
110 ...fp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/BuildWrapperPlugin.java
@@ -0,0 +1,110 @@
+package net.sf.eclipsefp.haskell.buildwrapper;
+
+import java.io.File;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+import net.sf.eclipsefp.haskell.scion.client.ScionInstance;
+import net.sf.eclipsefp.haskell.scion.client.ScionPlugin;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.ui.statushandlers.StatusManager;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class BuildWrapperPlugin extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "net.sf.eclipsefp.haskell.buildwrapper";
+
+ // The shared instance
+ private static BuildWrapperPlugin plugin;
+
+ private static Map<IProject, BWFacade> facades=new HashMap<IProject, BWFacade>();
+
+ /**
+ * The constructor
+ */
+ public BuildWrapperPlugin() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static BuildWrapperPlugin getDefault() {
+ return plugin;
+ }
+
+ public static BWFacade createFacade(IProject p,String bwPath,String cabalPath,Writer outStream){
+
+ IFile cf=ScionInstance.getCabalFile(p);
+ if (cf!=null){
+ BWFacade f=new BWFacade();
+ f.setBwPath(bwPath);
+ f.setCabalPath(cabalPath);
+ f.setCabalFile(cf.getLocation().toOSString());
+ f.setWorkingDir(new File(p.getLocation().toOSString()));
+ f.setOutStream(outStream);
+ facades.put(p, f);
+ return f;
+ }
+ return null;
+ }
+
+ public static BWFacade getFacade(IProject p){
+ return facades.get(p);
+ }
+
+ public static void logInfo(String message) {
+ log(Status.INFO, message, null);
+ }
+
+ public static void logDebug(String message) {
+ // log(Status.INFO, message, null);
+ }
+
+ public static void logWarning(String message, Throwable cause) {
+ log(Status.WARNING, message, cause);
+ }
+
+
+ public static void logError(String message, Throwable cause) {
+ log(Status.ERROR, message, cause);
+ }
+
+ public static void log(int severity, String message, Throwable cause) {
+ Status status = new Status(severity, ScionPlugin.getPluginId(), severity, message, cause);
+ logStatus(status);
+ }
+
+ public static void logStatus(IStatus status) {
+ StatusManager.getManager().handle(status);
+ }
+}
View
19 ...eclipsefp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/util/BWText.java
@@ -0,0 +1,19 @@
+package net.sf.eclipsefp.haskell.buildwrapper.util;
+
+import org.eclipse.osgi.util.NLS;
+
+/**
+ * Provides access to the internationalized UI texts.
+ *
+ * @author Thomas ten Cate
+ */
+public class BWText extends NLS {
+ public static String process_launch_error;
+ public static String process_parse_error;
+
+ private static final String BUNDLE_NAME = BWText.class.getPackage().getName() + ".bwtext"; //$NON-NLS-1$
+
+ static {
+ NLS.initializeMessages(BUNDLE_NAME, BWText.class);
+ }
+}
View
2 ...efp.haskell.buildwrapper/src/net/sf/eclipsefp/haskell/buildwrapper/util/bwtext.properties
@@ -0,0 +1,2 @@
+process_launch_error=Error while launching buildwrapper process
+process_parse_error=Cannot parse buildwrapper response as JSON Object
View
3 net.sf.eclipsefp.haskell.ui/META-INF/MANIFEST.MF
@@ -29,7 +29,8 @@ Require-Bundle: net.sf.eclipsefp.haskell.core,
org.eclipse.wst.css.ui;bundle-version="1.0.0";resolution:=optional,
org.eclipse.wst.jsdt.ui;bundle-version="1.0.0";resolution:=optional,
org.eclipse.wst.web.ui;bundle-version="1.1.0";resolution:=optional,
- org.eclipse.wst.xml.ui;bundle-version="1.1.0";resolution:=optional
+ org.eclipse.wst.xml.ui;bundle-version="1.1.0";resolution:=optional,
+ net.sf.eclipsefp.haskell.buildwrapper;bundle-version="2.1.1"
Bundle-ManifestVersion: 2
Export-Package: net.sf.eclipsefp.common.ui.dialog;uses:="org.eclipse.swt.widgets",
net.sf.eclipsefp.common.ui.preferences;
View
39 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/scion/ScionManager.java
@@ -6,6 +6,8 @@
import java.util.List;
import java.util.Set;
import net.sf.eclipsefp.haskell.browser.BrowserPlugin;
+import net.sf.eclipsefp.haskell.buildwrapper.BWFacade;
+import net.sf.eclipsefp.haskell.buildwrapper.BuildWrapperPlugin;
import net.sf.eclipsefp.haskell.core.HaskellCorePlugin;
import net.sf.eclipsefp.haskell.core.cabal.CabalImplementation;
import net.sf.eclipsefp.haskell.core.cabal.CabalImplementationManager;
@@ -811,6 +813,22 @@ private synchronized ScionInstance startInstance( final IProject project ) {
} catch( ScionServerStartupException ex ) {
reportServerStartupError( ex );
}
+
+ HaskellConsole cbw=getBWHaskellConsole( project );
+ Writer outStreamBw = cbw.createOutputWriter();
+ String bwPath="D:\\dev\\haskell\\jp-github\\eclipsefp\\buildwrapper\\dist\\build\\buildwrapper\\buildwrapper.exe";
+ final BWFacade f=BuildWrapperPlugin.createFacade(project, bwPath, CabalImplementationManager.getCabalExecutable(), outStreamBw );
+ if (f!=null){
+ new Job("BuildWrapper "+project.getName()){
+ @Override
+ protected IStatus run( final IProgressMonitor arg0 ) {
+ f.synchronize();
+ f.build( new BuildOptions().setOutput( true ) );
+ return Status.OK_STATUS;
+ }
+ }.schedule();
+
+ }
}
return instance;
@@ -865,6 +883,11 @@ private final String consoleName ( final IProject project ) {
return NLS.bind( UITexts.scion_console_title, projectName );
}
+ private final String bwconsoleName ( final IProject project ) {
+ String projectName = project != null ? project.getName() : UITexts.noproject;
+ return NLS.bind( UITexts.bw_console_title, projectName );
+ }
+
/** Spawn a built-in server build job */
synchronized void spawnBuildJob() {
if (internalBuilder == null) {
@@ -924,6 +947,22 @@ private HaskellConsole getHaskellConsole(final IProject project) {
return hCon;
}
+ private HaskellConsole getBWHaskellConsole(final IProject project) {
+ final String consoleName = bwconsoleName(project);
+ final IConsoleManager mgr = ConsolePlugin.getDefault().getConsoleManager();
+
+ for( IConsole c: mgr.getConsoles() ) {
+ if( c.getName().equals( consoleName ) ) {
+ return (HaskellConsole) c;
+ }
+ }
+
+ HaskellConsole hCon = new HaskellConsole( consoleName );
+
+ hCon.setWaterMarks( hConLowWater, hConHighWater );
+ return hCon;
+ }
+
/** Specialized Job class that manages building the built-in Scion server,
* providing some feedback to the user as the build progresses.
*
View
2 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/UITexts.java
@@ -246,6 +246,8 @@
public static String scion_preferences_title;
public static String scion_delta_error;
+ public static String bw_console_title;
+
public static String libraries_description;
public static String libraries_add_title;
public static String libraries_add_available_title;
View
2 net.sf.eclipsefp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/util/uitexts.properties
@@ -248,6 +248,8 @@ scion_preferences_title = Preferences related to Cabal, the Common Architecture
Building Applications and Libraries, and Scion, the Haskell IDE library
scion_delta_error = Error when processing resource delta from ScionManager
+bw_console_title = BuildWrapper output for project {0}
+
outline_sortByName=Sort by name
outline_sortByName_tooltip=Sort by name
outline_sortByName_description=Sort by name

0 comments on commit 49f15b4

Please sign in to comment.
Something went wrong with that request. Please try again.