/* * Copyright 2000-2010 JetBrains s.r.o. * * 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 jetbrains.buildServer.eclipse.agent.builder; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import jetbrains.buildServer.RunBuildException; import jetbrains.buildServer.agent.BuildRunnerContext; import jetbrains.buildServer.agent.runner.ProgramCommandLine; import jetbrains.buildServer.eclipse.EclipseConstants; import jetbrains.buildServer.eclipse.java.BuildDescriptor; import jetbrains.buildServer.eclipse.java.PlatformDescriptor; import jetbrains.buildServer.util.FileUtil; import org.apache.log4j.Logger; public class PluginsProjectBuilder extends FeatureBasedProjectBuilder { private static final String TEMPORARY_CONTAINER_FEATURE_ID = "org.eclipse.pde.container.feature"; private final static Logger LOG = Logger.getLogger(PluginsProjectBuilder.class); private File myFeatureRoot; public PluginsProjectBuilder(BuildRunnerContext buildRunnerContext, PlatformDescriptor platform, BuildDescriptor buildDescriptor) { super(buildRunnerContext, platform, buildDescriptor); } @Override public void init() throws RunBuildException { try { //create temporary 'org.eclipse.pde.container.feature' feature myFeatureRoot = createFeature(getBuildDescriptor().getTypeId()); } catch (Exception e) { throw new RunBuildException(e); } super.init(); } private File createFeature(final String... plugins) throws IOException { final File featuresFolder = getBuildDescriptor().getFeaturesFolder(); if (!featuresFolder.exists()) { featuresFolder.mkdirs(); LOG.debug(String.format("Absent 'features' folder created: '%s'", featuresFolder)); } final File containerFeature = new File(featuresFolder, TEMPORARY_CONTAINER_FEATURE_ID); containerFeature.mkdirs(); LOG.debug(String.format("Temporary container feature created: '%s'", containerFeature.getName())); //create the feature's content FileUtil.writeToFile(new File(containerFeature, "build.properties"), "pde=marker".getBytes()); final File featureFile = new File(containerFeature, "feature.xml"); BufferedWriter writer = new BufferedWriter(new FileWriter(featureFile)); writer.write("\n"); writer.write(String.format("\n", TEMPORARY_CONTAINER_FEATURE_ID)); for (final String pluginId : plugins) { writer.write(String.format("\n", pluginId, getBuildDescriptor().getTypeVersion(pluginId))); } writer.write("\n"); writer.flush(); writer.close(); return containerFeature; } @Override public ProgramCommandLine[] makeCommandLines() { return new ProgramCommandLine[] { makeCommandLinesFor(EclipseConstants.ECLIPSE_BUILD_TYPE_FEATURE, TEMPORARY_CONTAINER_FEATURE_ID) }; } //java -jar "C:\eclipse\eclipse-PDE-build\eclipse\plugins\org.eclipse.equinox.launcher_1.1.0.v20100507.jar" -application org.eclipse.ant.core.antRunner -buildfile "C:\eclipse\eclipse-PDE-build\eclipse\plugins\org.eclipse.pde.build_3.6.1.R36x_v20100823/scripts/build.xml" -DtopLevelElementType=feature -DbuildDirectory=Z:\teamcity\TeamCity-distr\TeamCity\buildAgent\work\d0951b78f57d07ec -DforceContextQualifier=12 -Dbuilder="Z:\teamcity\TeamCity-distr\TeamCity\buildAgent\work\d0951b78f57d07ec" -DtopLevelElementId=org.eclipse.pde.container.feature -Dp2.flavor=tooling -DjavacSource=1.5 -DjavacTarget=1.5 -Dbase=C:\eclipse\eclipse-PDE-build -DbaseLocation=C:\eclipse\eclipse-PDE-build\eclipse -DskipFetch=true -DskipBase=true -DskipMaps=true -Dinclude.children=true -DbuildTempFolder=Z:\teamcity\TeamCity-distr\TeamCity\buildAgent\work\d0951b78f57d07ec\tmp -Dfeature.temp.folder=Z:\teamcity\TeamCity-distr\TeamCity\buildAgent\work\d0951b78f57d07ec\tmp -DgenerateAPIDescription=true -DrunPackager=true -DjavacFailOnError=false -DarchivesFormat=*,*,*-folder -Dbaseos=* -Dbasews=* -Dbasearch=* //java -jar "C:\eclipse\eclipse-PDE-build\eclipse\plugins\org.eclipse.equinox.launcher_1.1.0.v20100507.jar" -application org.eclipse.ant.core.antRunner -buildfile "C:\eclipse\eclipse-PDE-build\eclipse\plugins\org.eclipse.pde.build_3.6.1.R36x_v20100823/scripts/build.xml" -DtopLevelElementType=feature -DbuildDirectory=Z:\teamcity\TeamCity-distr\TeamCity\buildAgent\work\d0951b78f57d07ec -DforceContextQualifier=12 -Dbuilder="Z:\teamcity\TeamCity-distr\TeamCity\buildAgent\work\d0951b78f57d07ec" -DtopLevelElementId=org.eclipse.pde.container.feature -Dp2.flavor=tooling -DjavacSource=1.5 -DjavacTarget=1.5 -Dbase=C:\eclipse\eclipse-PDE-build -DbaseLocation=C:\eclipse\eclipse-PDE-build\eclipse -DskipFetch=true -DskipBase=true -DskipMaps=true -Dinclude.children=true -DbuildTempFolder=Z:\teamcity\TeamCity-distr\TeamCity\buildAgent\work\d0951b78f57d07ec\tmp -Dfeature.temp.folder=Z:\teamcity\TeamCity-distr\TeamCity\buildAgent\work\d0951b78f57d07ec\tmp -DgenerateAPIDescription=true -DrunPackager=true -DjavacFailOnError=false -DarchivesFormat=*,*,*-antZip -Dbaseos=* -Dbasews=* -Dbasearch=* -DbuildLabel=. -DarchivePrefix="" -DcustomAssembly=Z:\teamcity\TeamCity-distr\TeamCity\buildAgent\work\d0951b78f57d07ec\customAssembly.xml -verbose>out 2>&1 @Override public void destroy() { // if (myFeatureRoot != null && myFeatureRoot.exists()) { // FileUtil.delete(myFeatureRoot); // LOG.debug(String.format("Drop temporary feature in '%s'", myFeatureRoot)); // myFeatureRoot = null; // } super.destroy(); } }