@Override public Iterable<Edge> getEdgesIncidentWith(AbstractProject<?, ?> project) { Set<Edge> artifactEdges = Sets.newHashSet(); if (copyartifactIsInstalled) { if (project instanceof FreeStyleProject) { FreeStyleProject proj = (FreeStyleProject) project; List<Builder> builders = proj.getBuilders(); for (Builder builder : builders) { if (builder instanceof CopyArtifact) { CopyArtifact caBuilder = (CopyArtifact) builder; String projectName = caBuilder.getProjectName(); Jenkins jenkins = Jenkins.getInstance(); AbstractProject<?, ?> projectFromName = jenkins.getItem(projectName, project.getParent(), AbstractProject.class); if (projectFromName != null) { artifactEdges.add(new CopyArtifactEdge(node(projectFromName), node(project))); } } } } } return artifactEdges; }
/** projectName in CopyArtifact build steps should be updated if a job is renamed */ public void testJobRename() throws Exception { FreeStyleProject other = createFreeStyleProject(), p = createProject(other.getName(), "", "", true, false, false); assertEquals( "before", other.getName(), ((CopyArtifact) p.getBuilders().get(0)).getProjectName()); String newName = other.getName() + "-new"; other.renameTo(newName); assertEquals("after", newName, ((CopyArtifact) p.getBuilders().get(0)).getProjectName()); // Test reference to a matrix configuration MatrixProject otherm = createMatrixProject(), mp = createMatrixProject(); mp.getBuildersList() .add( new CopyArtifact( otherm.getName() + "/FOO=$FOO", new SavedBuildSelector(), "", "", false, false)); assertEquals( "before", otherm.getName() + "/FOO=$FOO", ((CopyArtifact) mp.getBuilders().get(0)).getProjectName()); otherm.renameTo(newName = otherm.getName() + "-new"); assertEquals( "after", newName + "/FOO=$FOO", ((CopyArtifact) mp.getBuilders().get(0)).getProjectName()); }