protected List<MavenAbstractArtifactRecord> getArtifactRecordActions(MavenModuleSetBuild build) { List<MavenAbstractArtifactRecord> actions = Lists.newArrayList(); for (MavenBuild moduleBuild : build.getModuleLastBuilds().values()) { MavenAbstractArtifactRecord action = moduleBuild.getAction(MavenAbstractArtifactRecord.class); if (action != null) { actions.add(action); } } return actions; }
/** * Returns the modules which have not been build since the last successful aggregator build * though they should be because they had SCM changes. * This can happen when the aggregator build fails before it reaches the module. * * See JENKINS-5764 */ private Collection<ModuleName> getUnbuiltModulesSinceLastSuccessfulBuild() { Collection<ModuleName> unbuiltModules = new ArrayList<>(); MavenModuleSetBuild previousSuccessfulBuild = getPreviousSuccessfulBuild(); if (previousSuccessfulBuild == null) { LOGGER.log(Level.FINER, "no successful build from {0} yet; taking the first build instead", MavenModuleSetBuild.this); previousSuccessfulBuild = getParent().getFirstBuild(); } for (MavenModuleSetBuild previousBuild = previousSuccessfulBuild; previousBuild != null && previousBuild != MavenModuleSetBuild.this; previousBuild = previousBuild.getNextBuild()) { UnbuiltModuleAction unbuiltModuleAction = previousBuild.getAction(UnbuiltModuleAction.class); if (unbuiltModuleAction != null) { Collection<ModuleName> newUnbuiltModules = unbuiltModuleAction.getUnbuildModules(); LOGGER.log(Level.FINER, "considered {0} and consequently adding {1}", new Object[] {previousBuild, newUnbuiltModules}); unbuiltModules.addAll(newUnbuiltModules); } else { LOGGER.log(Level.FINER, "considered {0} but it has no list of unbuilt modules", previousBuild); } } LOGGER.log(Level.FINER, "unbuilt modules since last successful build of {0}: {1}", new Object[] {MavenModuleSetBuild.this, unbuiltModules}); return unbuiltModules; }
public ArgumentListBuilder intercept(ArgumentListBuilder mavenargs, MavenModuleSetBuild build) { // calling internal Method, which now (without MavenModuleSetBuil) can be tested easily return internalIntercept(mavenargs, build.getProject().isIncrementalBuild()); }
@SuppressWarnings("unchecked") public void run() { execute(new MavenModuleSetBuildExecution()); getProject().updateTransientActions(); }
public void run() { run(new RunnerImpl()); getProject().updateTransientActions(); }
/** * Estimates the duration overhead the {@link MavenModuleSetBuild} itself adds * to the sum of duration of the module builds. */ private long estimateModuleSetBuildDurationOverhead(int numberOfBuilds) { List<MavenModuleSetBuild> moduleSetBuilds = getPreviousBuildsOverThreshold(numberOfBuilds, Result.UNSTABLE); if (moduleSetBuilds.isEmpty()) { return 0; } long overhead = 0; for(MavenModuleSetBuild moduleSetBuild : moduleSetBuilds) { long sumOfModuleBuilds = 0; for (List<MavenBuild> builds : moduleSetBuild.getModuleBuilds().values()) { if (!builds.isEmpty()) { MavenBuild moduleBuild = builds.get(0); sumOfModuleBuilds += moduleBuild.getDuration(); } } overhead += Math.max(0, moduleSetBuild.getDuration() - sumOfModuleBuilds); } return Math.round((double)overhead / moduleSetBuilds.size()); }
EnvVars envVars = getEnvironment(listener); MavenInstallation mvn = project.getMaven(); if(mvn==null) MavenInformation mavenInformation = getModuleRoot().act( new MavenVersionCallable( mvn.getHome() )); setMavenVersionUsed( mavenVersion ); LOGGER.fine(getFullDisplayName()+" is building with mavenVersion " + mavenVersion + " from file " + mavenInformation.getVersionResourcePath()); for (BuildWrapper w : project.getBuildWrappersList()) wrappers.add(w); ParametersAction parameters = getAction(ParametersAction.class); if (parameters != null) parameters.createBuildWrappers(MavenModuleSetBuild.this,wrappers); Environment e = w.setUp(MavenModuleSetBuild.this, launcher, listener); if(e==null){ setResult(r = Result.FAILURE); return r; || !preBuild(listener,project.getPostbuilders()) || !preBuild(listener,project.getPublishers())){ setResult(r = FAILURE); return r; setResult(r = FAILURE); return r;
EnvVars envVars = getEnvironment(listener); MavenInstallation mvn = project.getMaven(); if(mvn==null) MavenInformation mavenInformation = getModuleRoot().act( new MavenVersionCallable( mvn.getHome() )); setMavenVersionUsed( mavenVersion ); for (BuildWrapper w : project.getBuildWrappersList()) wrappers.add(w); ParametersAction parameters = getAction(ParametersAction.class); if (parameters != null) parameters.createBuildWrappers(MavenModuleSetBuild.this,wrappers); mb.setBuiltOnStr( getBuiltOnStr() ); if (!MavenModuleSetBuild.this.getChangeSet().isEmptySet() && project.isIncrementalBuild()) { (!getChangeSetFor(m).isEmpty()) || (mb.getPreviousBuiltBuild().getResult().isWorseThan(Result.SUCCESS))) { changedModules.add(m.getModuleName().toString()); mb.setWorkspace(getModuleRoot().child(m.getRelativePath())); proxies.put(m.getModuleName(), mb.new ProxyImpl2(MavenModuleSetBuild.this,slistener)); FilePath pom = getModuleRoot().child(rootPOM); FilePath parentLoc = getWorkspace().child(rootPOM); if(!pom.exists() && parentLoc.exists())
try { getParent().updateNextBuildNumber(); Map<MavenModule, List<MavenBuild>> moduleBuilds = getModuleBuilds(); boolean modified = false; List<Action> actions = getActions(); Set<Class<? extends AggregatableAction>> individuals = new HashSet<>(); for (Action a : actions) { addAction(mar); modified = true; save(); getProject().updateTransientActions(); Util.createSymlink(getRootDir(), "../../modules/"+ moduleFsName +"/builds/"+newBuild.getId() /*ugly!*/, moduleFsName, StreamTaskListener.NULL);
/** * Computes the latest module builds that correspond to this build. * (when indivudual modules are built, a new ModuleSetBuild is not created, * but rather the new module build falls under the previous ModuleSetBuild) */ public Map<MavenModule,MavenBuild> getModuleLastBuilds() { Collection<MavenModule> mods = getParent().getModules(); // identify the build number range. [start,end) MavenModuleSetBuild nb = getNextBuild(); int end = nb!=null ? nb.getNumber() : Integer.MAX_VALUE; // preserve the order by using LinkedHashMap Map<MavenModule,MavenBuild> r = new LinkedHashMap<MavenModule,MavenBuild>(mods.size()); for (MavenModule m : mods) { MavenBuild b = m.getNearestOldBuild(end - 1); if(b!=null && b.getNumber()>=getNumber()) r.put(m,b); } return r; }
if (moduleSetBuild.getParent().isIncrementalBuild() && moduleSetBuild.getResult() != Result.SUCCESS && moduleSetBuild.getResult() != Result.UNSTABLE) { UnbuiltModuleAction action = moduleSetBuild.getAction(UnbuiltModuleAction.class); if (action == null) { action = new UnbuiltModuleAction(); moduleSetBuild.getActions().add(action); MavenModuleSetBuild previousParentBuild = moduleSetBuild.getPreviousBuild(); if (previousParentBuild != null) { UnbuiltModuleAction unbuiltModuleAction = previousParentBuild.getAction(UnbuiltModuleAction.class); if (unbuiltModuleAction != null) { unbuiltModuleAction.removeUnbuildModule(getParent().getModuleName()); try { previousParentBuild.save(); } catch (IOException e) { e.printStackTrace(); if (moduleSetBuild.getParent().isIncrementalBuild() && (moduleSetBuild.getResult() != Result.SUCCESS)) { MavenModuleSet mavenModuleSet = moduleSetBuild.getParent(); boolean isDeploying = false; Result deploymentThreshold = Result.SUCCESS; if (isDeploying && moduleSetBuild.getResult().isWorseThan(deploymentThreshold)) { UnbuiltModuleAction action = moduleSetBuild.getAction(UnbuiltModuleAction.class); if (action == null) { action = new UnbuiltModuleAction();
protected void post2(BuildListener listener) throws Exception { // asynchronous executions from the build might have left some unsaved state, // so just to be safe, save them all. for (MavenBuild b : getModuleLastBuilds().values()) b.save(); // at this point the result is all set, so ignore the return value if (!performAllBuildSteps(listener, project.getPublishers(), true)) setResult(FAILURE); if (!performAllBuildSteps(listener, project.getProperties(), true)) setResult(FAILURE); // aggregate all module fingerprints to us, // so that dependencies between module builds can be understood as // dependencies between module set builds. // TODO: we really want to implement this as a publisher, // but we don't want to ask for a user configuration, nor should it // show up in the persisted record. MavenFingerprinter.aggregate(MavenModuleSetBuild.this); }
public void deploy(MavenEmbedder embedder, ArtifactRepository deploymentRepository, TaskListener listener) throws MavenEmbedderException, IOException, ComponentLookupException, ArtifactDeploymentException { if(debug) listener.getLogger().println("Redeploying artifacts of "+parent+" timestamp="+parent.getTimestamp()); for (MavenBuild build : parent.getModuleLastBuilds().values()) { MavenArtifactRecord mar = build.getAction(MavenArtifactRecord.class); if(mar!=null) { if(debug) listener.getLogger().println("Deploying module: "+build+" timestamp="+build.getTimestamp()); mar.deploy(embedder,deploymentRepository,listener); } } } }
for (Map.Entry<MavenModule, MavenBuild> e : mavenModuleSetBuild.getModuleLastBuilds().entrySet()) { MavenBuild moduleBuild = e.getValue(); if (moduleBuild != null) { } else { if (mavenModuleSetBuild.getPreviousBuild() != null) { MavenModuleSetBuild prevBuild = mavenModuleSetBuild.getPreviousBuild(); AbstractBuild<?, ?> prevModuleBuild = prevBuild.getModuleLastBuilds().get(e.getKey()); if (prevModuleBuild.getResult() == null) { prevModuleBuild = BuildUtil.getPreviousBuiltBuild(prevModuleBuild);
@Override public void buildEnvVars(Map<String, String> env) { if (build.getWorkspace() == null) { if (!initialized && !(build.getProject().getScm() instanceof NullSCM)) { if (isFlexibleWrapsPublisher(build.getProject())) { buildListener.getLogger().println("Artifactory publisher is wrapped by the Flexible-Publish publisher. Build-Info-Maven3-Extractor is disabled."); return; resolver.getArtifactoryServer()); resolverContext = new ResolverContext(resolver.getArtifactoryServer(), resolver.getResolverDetails(), resolverCredentials.getCredentials(build.getProject()), resolver); env, build, buildListener, publisherContext, resolverContext, build.getWorkspace(), launcher); propertiesFilePath = configuration.getPropertiesFile(); } catch (Exception e) {
/** * Information about artifacts produced by Maven. */ @Exported public MavenAggregatedArtifactRecord getMavenArtifacts() { return getAction(MavenAggregatedArtifactRecord.class); }
/** * Estimates the duration overhead the {@link MavenModuleSetBuild} itself adds * to the sum of durations of the module builds. */ private long estimateModuleSetBuildDurationOverhead(int numberOfBuilds) { List<MavenModuleSetBuild> moduleSetBuilds = getParent().getEstimatedDurationCandidates(); if (moduleSetBuilds.isEmpty()) { return 0; } long overhead = 0; for(MavenModuleSetBuild moduleSetBuild : moduleSetBuilds) { long sumOfModuleBuilds = 0; for (List<MavenBuild> builds : moduleSetBuild.getModuleBuilds().values()) { if (!builds.isEmpty()) { MavenBuild moduleBuild = builds.get(0); sumOfModuleBuilds += moduleBuild.getDuration(); } } overhead += Math.max(0, moduleSetBuild.getDuration() - sumOfModuleBuilds); } return Math.round((double)overhead / moduleSetBuilds.size()); }
@Override public Object getDynamic(String token, StaplerRequest req, StaplerResponse rsp) { // map corresponding module build under this object if(token.indexOf('$')>0) { MavenModule m = getProject().getModule(token); if(m!=null) return m.getBuildByNumber(getNumber()); } return super.getDynamic(token,req,rsp); }
/** * Retrieve from the parent pom the path to the modules of the project */ private List<String> getMavenModules(MavenModuleSetBuild mavenBuild) throws IOException, InterruptedException { FilePath pathToModuleRoot = mavenBuild.getModuleRoot(); FilePath pathToPom = new FilePath(pathToModuleRoot, mavenBuild.getProject().getRootPOM(null)); return pathToPom.act(new MavenModulesExtractor()); }
PomParser.Result result = getModuleRoot().act(new PomParser(listener, mvn, mavenVersion, envVars, MavenModuleSetBuild.this)); poms = result.infos; mavenBuildInformation.modelParents.putAll(result.modelParents); getActions().add(new NeedsFullBuildAction()); getActions().add(new NeedsFullBuildAction()); } else {// this looks like a new module logger.println(Messages.MavenModuleSetBuild_DiscoveredModule(pom.name,pom.displayName)); mm = new MavenModule(project,pom,getNumber()); mm.onCreatedFromScratch(); modules.put(mm.getModuleName(),mm); m.updateNextBuildNumber(getNumber());