Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [buckminster-dev] Hudson plugin and provisioning

Hi again,

installation still fails under windows using 0.9.5, some files could not be found.

Yes, Hudson has to ability to execute sh scripts on Windows machines, so that is as expected.

Hm, I watched hud-son spawning sh.exe from where it was found in PATH, there did not seem to be any special treatment for sh scripts. Is this really expected to work out-ofthe-box?

I grabbed the sources and tried to debug and fix the installation issues under windows.
Find attached a patch that implements the following changes: The installation mechanism no longer generates and runs a shell script but spawns processes for the necessary installation steps (i.e. use the directoy to install buckminster and then call buckminster itself to add additional features). The only OS-specific part is now the selection of the respective start scripts (director vs. director.bat, same for buckminster), the rest is the same for all OSes. Because the plugin now starts the processes directly and checks their return values, the installation will also fail if any of the installation commands fails. This did not work in my first try (where I created and ran a .bat file to perform the installation).

The patch has been created against SVN Revision 29269 and also includes a small fix in EclipseBuckminsterBuilder (ran into an exception on the configuration page).

One more thing I noticed: after updating to 0.9.5, the drop down box on the auto install configuration page is empty unless userContent/buckminster/buckminster.json exists. A default installer configuration seems to be missing? Or maybe something went wrong during my update.

Regards,
Daniel


Daniel Weber wrote:
Hi Johannes,

All pending issues have been implemented and spaces in the path should no longer become URI encoded. So if you want to give it another shot, 0.9.5 should be available in the update center in a few hours.

thanks for addressing this so quickly :)

The new version did not show up yet, I'll give it a try as soon as it is available. The proxy issue I encountered has already been reported, see http://issues.hudson-ci.org/browse/HUDSON-5271.

Cheers,
Daniel




diff --git src/main/java/hudson/plugins/buckminster/BuckminsterInstallation.java src/main/java/hudson/plugins/buckminster/BuckminsterInstallation.java
index 24165bf..98ed23f 100644
--- src/main/java/hudson/plugins/buckminster/BuckminsterInstallation.java
+++ src/main/java/hudson/plugins/buckminster/BuckminsterInstallation.java
@@ -6,6 +6,7 @@ package hudson.plugins.buckminster;
 import hudson.EnvVars;
 import hudson.Extension;
 import hudson.FilePath;
+import hudson.Launcher.ProcStarter;
 import hudson.model.EnvironmentSpecific;
 import hudson.model.Hudson;
 import hudson.model.Node;
@@ -117,37 +118,40 @@ public class BuckminsterInstallation extends ToolInstallation implements Environ
 				throws IOException, InterruptedException {
 			return null;
 		}
-		
-		@Override
-		public FilePath performInstallation(ToolInstallation tool, Node node,
-				TaskListener log) throws IOException, InterruptedException {
-			FilePath director = super.performInstallation(tool, node, log);
-			FilePath buckminsterDir = director.child("buckminster");
-			if(buckminsterDir.exists())
-			{
-		    	FilePath executableWin = buckminsterDir.child("buckminster.bat");
-		    	FilePath executableUnix = buckminsterDir.child("buckminster");
-		    	if(executableUnix.exists() || executableWin.exists())
-				//	here we could do an update...
-		    		return buckminsterDir;
-			}
-//	        FilePath expected = preferredLocation(tool, node);
-	        BuckminsterInstallable inst = (BuckminsterInstallable) getInstallable();
-	        String command = CommandLineBuilder.createInstallScript(inst, director, node, log);
-	        FilePath script = buckminsterDir.createTextTempFile("hudson", ".sh", command);
-	        try {
-	            String[] cmd = {"sh", "-e", script.getRemote()};
-	            int r = node.createLauncher(log).launch().cmds(cmd).stdout(log).pwd(buckminsterDir).join();
-	            if (r != 0) {
-	                throw new IOException("Command returned status " + r);
-	            }
-	        } finally {
-	            script.delete();
-	        }
-	        return buckminsterDir;
-			
-		}
-		
+
+      @Override
+      public FilePath performInstallation(ToolInstallation tool, Node node,
+            TaskListener log) throws IOException, InterruptedException
+      {
+         FilePath director = super.performInstallation(tool, node, log);
+         FilePath buckminsterDir = director.child("buckminster");
+         if(buckminsterDir.exists())
+         {
+            FilePath executableWin = buckminsterDir.child("buckminster.bat");
+            FilePath executableUnix = buckminsterDir.child("buckminster");
+            if(executableUnix.exists() || executableWin.exists())
+               // here we could do an update...
+               return buckminsterDir;
+         }
+         else
+         {
+            // Must exist so that it can be used as PWD
+            buckminsterDir.mkdirs();
+         }
+         // FilePath expected = preferredLocation(tool, node);
+         BuckminsterInstallable inst = (BuckminsterInstallable)getInstallable();
+         for(ProcStarter starter : CommandLineBuilder.createInstallationCommandStarters(
+               inst, director, node, log))
+         {
+            int r = starter.pwd(buckminsterDir).join();
+            if(r != 0)
+            {
+               throw new IOException("Command returned status " + r);
+            }
+         }
+         return buckminsterDir;
+      }
+
 		@Extension
 		public static final class DescriptorImpl extends
 				DownloadFromUrlInstaller.DescriptorImpl<BuckminsterInstaller> {
diff --git src/main/java/hudson/plugins/buckminster/EclipseBuckminsterBuilder.java src/main/java/hudson/plugins/buckminster/EclipseBuckminsterBuilder.java
index 6cdb47b..06be49d 100644
--- src/main/java/hudson/plugins/buckminster/EclipseBuckminsterBuilder.java
+++ src/main/java/hudson/plugins/buckminster/EclipseBuckminsterBuilder.java
@@ -318,7 +318,7 @@ public class EclipseBuckminsterBuilder extends Builder {
             FilePath path = project.getSomeWorkspace();
             if(path==null)
             	//we tried, but we couldn't get a workspace
-            	FormValidation.ok();
+            return FormValidation.ok();
         	return path.validateRelativePath(value, true, true);
         }
 		
diff --git src/main/java/hudson/plugins/buckminster/command/CommandLineBuilder.java src/main/java/hudson/plugins/buckminster/command/CommandLineBuilder.java
index f2d07ee..28301a5 100644
--- src/main/java/hudson/plugins/buckminster/command/CommandLineBuilder.java
+++ src/main/java/hudson/plugins/buckminster/command/CommandLineBuilder.java
@@ -1,6 +1,8 @@
 package hudson.plugins.buckminster.command;
 
 import hudson.FilePath;
+import hudson.Functions;
+import hudson.Launcher.ProcStarter;
 import hudson.model.AbstractBuild;
 import hudson.model.BuildListener;
 import hudson.model.Computer;
@@ -297,42 +299,64 @@ public class CommandLineBuilder {
 		}
 		throw new FileNotFoundException("No equinox launcher jar has been found in "+pluginDir.getCanonicalPath());
 	}
-	
-	public static String createInstallScript(BuckminsterInstallable installable, FilePath toolDir, Node node, TaskListener log) throws MalformedURLException, IOException, InterruptedException
-	{
-		FilePath directorDir = toolDir.child("director");
-		String directorDirPath = directorDir.absolutize().toURI().getPath();
-		FilePath buckyDir = toolDir.child("buckminster");
-		String buckyDirPath = buckyDir.absolutize().toURI().getPath();
-		List<JDK> jdks = Hudson.getInstance().getJDKs();
-		String vmArgument = "";
-		if(jdks!=null && jdks.size()>0)
-		{
-			JDK jdk = Hudson.getInstance().getJDKs().get(0);
-			jdk = jdk.forNode(node, log);
-			jdk = jdk.forEnvironment(Computer.currentComputer().getEnvironment());
-			File javaBinDir = jdk.getBinDir(); 
-			File javaExecutable = new File(javaBinDir,"java");
-			vmArgument = "-vm "+"\""+javaExecutable.getCanonicalPath()+"\"";
-		}
 
-		//TODO: put IU to JSON
-		String command = "{0}/director {1} -r \"{2}\" -d \"{3}\" -p Buckminster -i \"{4}\"";
-		command = MessageFormat.format(command, directorDirPath,vmArgument ,installable.repositoryURL, buckyDirPath, installable.iu);
-		StringBuilder builder = new StringBuilder(command);
-		for (Repository repo : installable.repositories) {
-
-			for (Feature feature : repo.features) {
-				builder.append("\n");
-				command = "{0}/buckminster {1} install {2} {3}";
-				command = MessageFormat.format(command, buckyDirPath,vmArgument, repo.url,feature.id);
-				builder.append(command);
-				builder.append("\n");
-				command = "echo \"Installed Feature {0} from {1}\"";
-				command = MessageFormat.format(command, feature.id, repo.url);
-				builder.append(command);
-			}
-		}
-		return builder.toString();
-	}
-}
\ No newline at end of file
+	public static List<ProcStarter> createInstallationCommandStarters(
+         BuckminsterInstallable installable, FilePath toolDir, Node node, TaskListener log)
+         throws IOException, InterruptedException
+   {
+      FilePath directorDir = toolDir.child("director");
+      FilePath buckyDir = toolDir.child("buckminster");
+      String buckyDirPath = buckyDir.absolutize().getRemote();
+      List<JDK> jdks = Hudson.getInstance().getJDKs();
+      String vmArgument = "";
+      if(jdks != null && jdks.size() > 0)
+      {
+         JDK jdk = Hudson.getInstance().getJDKs().get(0);
+         jdk = jdk.forNode(node, log);
+         jdk = jdk.forEnvironment(Computer.currentComputer().getEnvironment());
+         File javaBinDir = jdk.getBinDir();
+         File javaExecutable = new File(javaBinDir, "java");
+         vmArgument = "-vm " + "\"" + javaExecutable.getCanonicalPath() + "\"";
+      }
+
+      List<ProcStarter> cmds = new ArrayList<ProcStarter>();
+      // TODO: put IU to JSON
+      final String director = directorDir.child(directorScriptName()).absolutize()
+            .getRemote();
+      String[] command = { director, vmArgument, "-r",
+            quote(installable.repositoryURL), "-d", quote(buckyDirPath), "-p",
+            "Buckminster", "-i", quote(installable.iu) };
+      cmds.add(node.createLauncher(log).launch().cmds(command).stdout(log));
+      final String bucky = buckyDir.child(buckyScriptName()).absolutize().getRemote();
+      for(Repository repo : installable.repositories)
+      {
+         for(Feature feature : repo.features)
+         {
+            String installFeatureCmd[] = { bucky, vmArgument, "install", repo.url,
+                  feature.id };
+            cmds.add(node.createLauncher(log).launch().cmds(installFeatureCmd)
+                  .stdout(log));
+         }
+      }
+      return cmds;
+   }
+
+   private static String buckyScriptName()
+   {
+      if(Functions.isWindows())
+         return "buckminster.bat";
+      return "buckminster";
+   }
+
+   private static String directorScriptName()
+   {
+      if(Functions.isWindows())
+         return "director.bat";
+      return "director";
+   }
+
+   private static String quote(final String original)
+   {
+      return "\"" + original + "\"";
+   }
+}

Back to the top