summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorRodrigo Fraxino Araujo2012-04-26 17:19:34 (EDT)
committer Otavio Pontes2012-04-26 17:46:35 (EDT)
commitb178c605f58fe9d56abfcfa2d6c98b95df079dbd (patch)
tree535c1e88c98f5c7a62d2023dc45faa0b1100728a
parent4ad8617a36ef30b438f1fc275e75ec1910b84bc4 (diff)
downloadorg.eclipse.linuxtools-b178c605f58fe9d56abfcfa2d6c98b95df079dbd.zip
org.eclipse.linuxtools-b178c605f58fe9d56abfcfa2d6c98b95df079dbd.tar.gz
org.eclipse.linuxtools-b178c605f58fe9d56abfcfa2d6c98b95df079dbd.tar.bz2
Added support to create and export RPM files remotely.
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.core/META-INF/MANIFEST.MF3
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/RPMBuild.java207
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/RPMProjectCreator.java81
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.rpmlint/src/org/eclipse/linuxtools/internal/rpm/rpmlint/builder/RpmlintPreVisitor.java5
4 files changed, 218 insertions, 78 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.core/META-INF/MANIFEST.MF b/rpm/org.eclipse.linuxtools.rpm.core/META-INF/MANIFEST.MF
index f55af8a..73b2d4e 100644
--- a/rpm/org.eclipse.linuxtools.rpm.core/META-INF/MANIFEST.MF
+++ b/rpm/org.eclipse.linuxtools.rpm.core/META-INF/MANIFEST.MF
@@ -14,3 +14,6 @@ Require-Bundle: org.eclipse.core.resources,
Export-Package:
org.eclipse.linuxtools.rpm.core,
org.eclipse.linuxtools.rpm.core.utils
+Import-Package: org.eclipse.core.filesystem,
+ org.eclipse.linuxtools.profiling.launch,
+ org.eclipse.ui.console
diff --git a/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/RPMBuild.java b/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/RPMBuild.java
index 6a0b24f..65e3a22 100644
--- a/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/RPMBuild.java
+++ b/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/internal/rpm/core/utils/RPMBuild.java
@@ -10,8 +10,12 @@
*******************************************************************************/
package org.eclipse.linuxtools.internal.rpm.core.utils;
+import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.io.OutputStream;
+import java.net.URI;
+import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -19,12 +23,22 @@ import java.util.List;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.preferences.DefaultScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.linuxtools.profiling.launch.IRemoteCommandLauncher;
+import org.eclipse.linuxtools.profiling.launch.IRemoteProxyManager;
+import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager;
import org.eclipse.linuxtools.rpm.core.IProjectConfiguration;
import org.eclipse.linuxtools.rpm.core.IRPMConstants;
import org.eclipse.linuxtools.rpm.core.utils.Utils;
+import org.eclipse.ui.console.ConsolePlugin;
+import org.eclipse.ui.console.IConsole;
+import org.eclipse.ui.console.MessageConsole;
+import org.eclipse.ui.console.MessageConsoleStream;
+
/**
* A utility class for executing rpmbuild commands.
@@ -38,29 +52,52 @@ public class RPMBuild {
private String rpmBuildCmd;
+ private String buildFolder;
+
/**
* Constructs a new object.
*
- * @param config
- * the RPM configuration to use
+ * @param config the RPM configuration to use
*/
public RPMBuild(IProjectConfiguration config) {
IEclipsePreferences node = DefaultScope.INSTANCE.getNode(IRPMConstants.RPM_CORE_ID);
rpmBuildCmd = node.get(IRPMConstants.RPMBUILD_CMD, ""); //$NON-NLS-1$
- String[] tmpMacroDefines = {
- rpmBuildCmd,
- "-v", //$NON-NLS-1$
- DEFINE, "_sourcedir " //$NON-NLS-1$
- + config.getSourcesFolder().getLocation().toOSString(),
- DEFINE, "_srcrpmdir " + //$NON-NLS-1$
- config.getSrpmsFolder().getLocation().toOSString(),
- DEFINE, "_builddir " + //$NON-NLS-1$
- config.getBuildFolder().getLocation().toOSString(),
- DEFINE, "_rpmdir " + //$NON-NLS-1$
- config.getRpmsFolder().getLocation().toOSString(),
- DEFINE, "_specdir " + //$NON-NLS-1$
- config.getSpecsFolder().getLocation().toOSString() };
- this.macroDefines = tmpMacroDefines;
+ if (config.getSourcesFolder().getLocation()==null) {
+ buildFolder = config.getBuildFolder().getLocationURI().toString();
+ String fullRemoteDirectory = config.getSourcesFolder().getLocationURI().toString();
+ String host = config.getSourcesFolder().getLocationURI().getHost();
+ int startIndex = fullRemoteDirectory.indexOf(host)+host.length();
+ String remoteDirectory = fullRemoteDirectory.substring(startIndex);
+ String[] tmpMacroDefines = {
+ // rpmBuildCmd,
+ "-v", //$NON-NLS-1$
+ DEFINE, "_sourcedir " + //$NON-NLS-1$
+ remoteDirectory + "/" + IRPMConstants.SOURCES_FOLDER, //$NON-NLS-1$
+ DEFINE, "_srcrpmdir " + //$NON-NLS-1$
+ remoteDirectory + "/" + IRPMConstants.SRPMS_FOLDER, //$NON-NLS-1$
+ DEFINE, "_builddir " + //$NON-NLS-1$
+ remoteDirectory + "/" + IRPMConstants.BUILD_FOLDER, //$NON-NLS-1$
+ DEFINE, "_rpmdir " + //$NON-NLS-1$
+ remoteDirectory + "/" + IRPMConstants.RPMS_FOLDER, //$NON-NLS-1$
+ DEFINE, "_specdir " + //$NON-NLS-1$
+ remoteDirectory + "/" + IRPMConstants.SPECS_FOLDER, }; //$NON-NLS-1$
+ this.macroDefines = tmpMacroDefines;
+ } else {
+ String[] tmpMacroDefines = {
+ rpmBuildCmd,
+ "-v", //$NON-NLS-1$
+ DEFINE, "_sourcedir " //$NON-NLS-1$
+ + config.getBuildFolder().getLocation().toOSString() + "/" + IRPMConstants.SOURCES_FOLDER, //$NON-NLS-1$
+ DEFINE, "_srcrpmdir " + //$NON-NLS-1$
+ config.getBuildFolder().getLocation().toOSString() + "/" + IRPMConstants.SRPMS_FOLDER, //$NON-NLS-1$
+ DEFINE, "_builddir " + //$NON-NLS-1$
+ config.getBuildFolder().getLocation().toOSString(),
+ DEFINE, "_rpmdir " + //$NON-NLS-1$
+ config.getBuildFolder().getLocation().toOSString() + "/" + IRPMConstants.RPMS_FOLDER, //$NON-NLS-1$
+ DEFINE, "_specdir " + //$NON-NLS-1$
+ config.getBuildFolder().getLocation().toOSString() + "/" + IRPMConstants.SPECS_FOLDER}; //$NON-NLS-1$
+ this.macroDefines = tmpMacroDefines;
+ }
}
/**
@@ -70,44 +107,21 @@ public class RPMBuild {
* @param outStream The stream to write the output to.
* @throws CoreException If the operation fails.
*/
- public void buildPrep(IResource specFile, OutputStream outStream)
- throws CoreException {
- List<String> command = new ArrayList<String>();
- command.addAll(Arrays.asList(macroDefines));
- command.add("-bp"); //$NON-NLS-1$
- command.add(specFile.getLocation().toString());
- try {
- Utils.runCommand(outStream,
- command.toArray(new String[command.size()]));
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID,
- e.getMessage(), e));
- }
+ public void buildPrep(IResource specFile, OutputStream outStream) throws CoreException {
+ build(specFile, outStream, "-bp"); //$NON-NLS-1$
}
+
/**
* Builds a binary RPM for a given spec file.
*
- * @param specFile
- * the spec file
- * @param outStream
- * The stream to write the output to.
+ * @param specFile the spec file
+ * @param outStream The stream to write the output to.
* @return The return code of the build job.
- * @throws CoreException
- * if the operation fails
+ * @throws CoreException if the operation fails
*/
public int buildBinary(IResource specFile, OutputStream outStream) throws CoreException {
- List<String> command = new ArrayList<String>();
- command.addAll(Arrays.asList(macroDefines));
- command.add("-bb"); //$NON-NLS-1$
- command.add(specFile.getLocation().toString());
- try {
- return Utils.runCommand(outStream,
- command.toArray(new String[command.size()]));
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID,
- e.getMessage(), e));
- }
+ return build(specFile, outStream, "-bb"); //$NON-NLS-1$
}
/**
@@ -116,43 +130,98 @@ public class RPMBuild {
* @param specFile the spec file
* @param outStream The stream to write the output to.
* @return The return code of the build job.
- * @throws CoreException
- * if the operation fails
+ * @throws CoreException if the operation fails
*/
public int buildAll(IResource specFile, OutputStream outStream) throws CoreException {
- List<String> command = new ArrayList<String>();
- command.addAll(Arrays.asList(macroDefines));
- command.add("-ba"); //$NON-NLS-1$
- command.add(specFile.getLocation().toString());
- try {
- return Utils.runCommand(outStream, command
- .toArray(new String[command.size()]));
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID,
- e.getMessage(), e));
- }
+ return build(specFile, outStream, "-ba"); //$NON-NLS-1$
}
+
/**
* Builds a source RPM for a given spec file.
*
* @param specFile the spec file
* @param outStream The stream to write the output to.
* @return The return code of the build job.
- * @throws CoreException
- * if the operation fails
+ * @throws CoreException if the operation fails
*/
+
public int buildSource(IResource specFile, OutputStream outStream) throws CoreException {
+ return build(specFile, outStream, "-bs"); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * Operations for actually running rpmbuild binary
+ *
+ * @param specFile The specfile used by rpmbuild
+ * @param outStream The stream to write the output to.
+ * @param buildParameter rpmbuild parameters
+ * @return The return code of the build job.
+ * @throws CoreException if the operation fails
+ * @since 0.4
+ */
+ public int build(IResource specFile, OutputStream outStream, String buildParameter) throws CoreException {
List<String> command = new ArrayList<String>();
+ IRemoteProxyManager rmtProxyMgr;
+ IRemoteCommandLauncher rmtCmdLauncher = null;
command.addAll(Arrays.asList(macroDefines));
- command.add("-bs"); //$NON-NLS-1$
- command.add(specFile.getLocation().toString());
- try {
- return Utils.runCommand(outStream, command
- .toArray(new String[command.size()]));
- } catch (IOException e) {
- throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID,
- e.getMessage(), e));
+ command.add(buildParameter);
+ String remoteSpec = ""; //$NON-NLS-1$
+ if (specFile.getLocation()==null) {
+ rmtProxyMgr = RemoteProxyManager.getInstance();
+ try {
+ rmtCmdLauncher = rmtProxyMgr.getLauncher(new URI(buildFolder));
+ } catch (URISyntaxException e1) {
+ throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID,
+ e1.getMessage(), e1));
+
+ }
+ String host = specFile.getLocationURI().getHost();
+ int startIndex = buildFolder.indexOf(host)+host.length();
+ remoteSpec = specFile.getLocationURI().toString().substring(startIndex);
+ command.add(remoteSpec);
+ String empty[] = new String[0];
+ Process pProxy = rmtCmdLauncher.execute(Path.fromOSString(rpmBuildCmd), command.toArray(new String[command.size()]), empty, null, new NullProgressMonitor());
+ MessageConsole console = new MessageConsole("rpmbuild", null); //$NON-NLS-1$
+ console.activate();
+ ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ console });
+ MessageConsoleStream stream = console.newMessageStream();
+
+ if (pProxy != null){
+ BufferedReader error = new BufferedReader(new InputStreamReader(pProxy.getErrorStream()));
+ String err;
+ try {
+ err = error.readLine();
+ while(err != null){
+ stream.println(err);
+ err = error.readLine();
+ }
+ error.close();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(pProxy.getInputStream()));
+ String readLine = reader.readLine();
+ while (readLine!=null) {
+ stream.println(readLine);
+ readLine=reader.readLine();
+ }
+ reader.close();
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID,
+ e.getMessage(), e));
+ }
+ }
+ return Status.OK_STATUS.getCode();
+
+ } else{
+ command.add(specFile.getLocation().toString());
+ try {
+ return Utils.runCommand(outStream, command
+ .toArray(new String[command.size()]));
+ } catch (IOException e) {
+ throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID,
+ e.getMessage(), e));
+ }
}
}
+
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/RPMProjectCreator.java b/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/RPMProjectCreator.java
index 80c7fb1..48e6b2f 100644
--- a/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/RPMProjectCreator.java
+++ b/rpm/org.eclipse.linuxtools.rpm.core/src/org/eclipse/linuxtools/rpm/core/RPMProjectCreator.java
@@ -10,6 +10,11 @@
************************************************************************/
package org.eclipse.linuxtools.rpm.core;
+import java.net.URI;
+import java.net.URISyntaxException;
+
+import org.eclipse.core.filesystem.EFS;
+import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
@@ -18,7 +23,13 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy;
+import org.eclipse.linuxtools.profiling.launch.RemoteProxyManager;
+
+
/**
* Utility class to ease creation of RPM projects.
@@ -37,7 +48,7 @@ public class RPMProjectCreator {
public RPMProjectCreator(RPMProjectLayout layout) {
this.layout = layout;
}
-
+
/**
* Creates the utility class with the default(RPMBuild) layout.
*/
@@ -58,22 +69,38 @@ public class RPMProjectCreator {
IProject project = root.getProject(projectName);
IProjectDescription description = ResourcesPlugin.getWorkspace()
.newProjectDescription(project.getName());
+ String parsedIPathString = null;
if (!Platform.getLocation().equals(projectPath))
- description.setLocation(projectPath);
- description
- .setNatureIds(new String[] { IRPMConstants.RPM_NATURE_ID });
+ parsedIPathString = projectPath.toString().replaceFirst(":/", "://"); //$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ description.setLocationURI(new URI(parsedIPathString));
+ } catch (URISyntaxException e) {
+ throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID,
+ e.getMessage(), e));
+ }
+
+
+ description.setNatureIds(new String[] { IRPMConstants.RPM_NATURE_ID });
project.create(description, monitor);
+
monitor.worked(10);
project.open(monitor);
- if (layout.equals(RPMProjectLayout.RPMBUILD)) {
- createDirs(monitor, project);
+ if (projectPath.toString().indexOf(':')!=-1) {
+ if (layout.equals(RPMProjectLayout.RPMBUILD)) {
+ createDirsRemote(monitor, project, parsedIPathString);
+ }
+ } else {
+ if (layout.equals(RPMProjectLayout.RPMBUILD)) {
+ createDirs(monitor, project);
+ }
}
latest=project;
+
} catch (CoreException e) {
e.printStackTrace();
}
}
-
+
/**
* Returns the latest project created.
* @return The last created project.
@@ -84,16 +111,54 @@ public class RPMProjectCreator {
private void createDirs(IProgressMonitor monitor, IProject project)
throws CoreException {
+
project.getFolder(IRPMConstants.SPECS_FOLDER).create(true, true,
monitor);
project.getFolder(IRPMConstants.SOURCES_FOLDER).create(true, true,
monitor);
IFolder buildFolder = project.getFolder(IRPMConstants.BUILD_FOLDER);
+
buildFolder.create(true, true, monitor);
buildFolder.setHidden(true);
project.getFolder(IRPMConstants.RPMS_FOLDER)
- .create(true, true, monitor);
+ .create(true, true, monitor);
project.getFolder(IRPMConstants.SRPMS_FOLDER).create(true, true,
monitor);
}
+
+ private void createDirsRemote(IProgressMonitor monitor, IProject project, String parsedIPathString)
+ throws CoreException {
+ IRemoteFileProxy proxy = null;
+ try {
+ proxy = RemoteProxyManager.getInstance().getFileProxy(new URI(parsedIPathString));
+ } catch (URISyntaxException e) {
+ throw new CoreException(new Status(IStatus.ERROR, IRPMConstants.RPM_CORE_ID,
+ e.getMessage(), e));
+ }
+
+ IFileStore iFileStoreSpecs = proxy.getResource(IRPMConstants.SPECS_FOLDER);
+ iFileStoreSpecs.mkdir(EFS.NONE, monitor);
+ project.getFolder(IRPMConstants.SPECS_FOLDER).create(true, true, monitor);
+
+ IFileStore iFileStoreSources = proxy.getResource(IRPMConstants.SOURCES_FOLDER);
+ iFileStoreSources.mkdir(EFS.NONE, monitor);
+ project.getFolder(IRPMConstants.SOURCES_FOLDER).create(true, true, monitor);
+
+ IFileStore iFileStoreBuild = proxy.getResource(IRPMConstants.BUILD_FOLDER);
+ iFileStoreBuild.mkdir(EFS.NONE, monitor);
+ IFolder buildFolder = project.getFolder(IRPMConstants.BUILD_FOLDER);
+ buildFolder.create(true, true, monitor);
+ buildFolder.setHidden(true);
+
+ IFileStore iFileStoreRPMs = proxy.getResource(IRPMConstants.RPMS_FOLDER);
+ iFileStoreRPMs.mkdir(EFS.NONE, monitor);
+ project.getFolder(IRPMConstants.RPMS_FOLDER).create(true, true, monitor);
+
+ IFileStore iFileStoreSRPMs = proxy.getResource(IRPMConstants.SRPMS_FOLDER);
+ iFileStoreSRPMs.mkdir(EFS.NONE, monitor);
+ project.getFolder(IRPMConstants.SRPMS_FOLDER).create(true, true, monitor);
+
+
+ }
+
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.rpmlint/src/org/eclipse/linuxtools/internal/rpm/rpmlint/builder/RpmlintPreVisitor.java b/rpm/org.eclipse.linuxtools.rpm.rpmlint/src/org/eclipse/linuxtools/internal/rpm/rpmlint/builder/RpmlintPreVisitor.java
index f1f9175..65c70c8 100644
--- a/rpm/org.eclipse.linuxtools.rpm.rpmlint/src/org/eclipse/linuxtools/internal/rpm/rpmlint/builder/RpmlintPreVisitor.java
+++ b/rpm/org.eclipse.linuxtools.rpm.rpmlint/src/org/eclipse/linuxtools/internal/rpm/rpmlint/builder/RpmlintPreVisitor.java
@@ -29,7 +29,10 @@ public class RpmlintPreVisitor implements IResourceVisitor {
.getFileExtension())) {
// we previsiting resource to be able to run rpmlint command
// only once. That improve drasticaly the perfs.
- paths.add(resource.getLocation().toOSString());
+ if (resource.getLocation()==null) {
+ paths.add(resource.getLocationURI().toString());
+ }
+ else paths.add(resource.getLocation().toOSString());
}
return true;
}