Skip to content

Commit

Permalink
[JENKINS-59342] Use the Jenkins rootdir path
Browse files Browse the repository at this point in the history
  • Loading branch information
Dohbedoh committed Oct 21, 2019
1 parent faaf96d commit cbf1261
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.util.logging.Level;

/**
Expand All @@ -41,12 +42,14 @@ public AbstractItemDirectoryComponent(String includes, String excludes, boolean
@Override
public void addContents(@NonNull Container container, @NonNull AbstractItem item) {
try {
list(item.getRootDir(), new FileVisitor() {
File itemRootDir = item.getRootDir();
Path relativeToRoot = new File(Jenkins.get().getRootDir(), "jobs").toPath()
.relativize(itemRootDir.toPath());
list(itemRootDir, new FileVisitor() {

@Override
public void visitSymlink(File link, String target, String relativePath) {
container.add(new PrintedContent("items/{0}/{1}",
item.getFullName(), relativePath) {
container.add(new PrintedContent("items/{0}/{1}", relativeToRoot.toString(), relativePath) {

@Override
protected void printTo(PrintWriter out) {
Expand All @@ -55,14 +58,14 @@ protected void printTo(PrintWriter out) {

@Override
public boolean shouldBeFiltered() {
return false;
return true;
}
});
}

@Override
public void visit(File file, String s) {
container.add(new FileContent("items/{0}/{1}", new String[]{item.getFullName(), s}, file));
container.add(new FileContent("items/{0}/{1}", new String[]{relativeToRoot.toString(), s}, file));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Path;
import java.util.logging.Level;

/**
Expand All @@ -41,31 +42,30 @@ public RunDirectoryComponent(String includes, String excludes, boolean defaultEx
@Override
public void addContents(@NonNull Container container, @NonNull Run item) {
try {
String relativeToParentPath = item.getParent().getRootDir().toPath().relativize(item.getRootDir().toPath()).toString();
File itemRootDir = item.getRootDir();
Path relativeToRoot = new File(Jenkins.get().getRootDir(), "jobs").toPath()
.relativize(itemRootDir.toPath());
list(item.getRootDir(), new FileVisitor() {

@Override
public void visitSymlink(File link, String target, String relativePath) {
container.add(new PrintedContent("items/{0}/{1}/{2}",
item.getParent().getFullName(), relativeToParentPath, relativePath) {
container.add(new PrintedContent("items/{0}/{1}", relativeToRoot.toString(), relativePath) {

@Override
protected void printTo(PrintWriter out) {
out.println("symlink -> " + target);
}

@Override
public boolean shouldBeFiltered() {
return false;
return true;
}
});
}

@Override
public void visit(File file, String s) {
container.add(new FileContent(
"items/{0}/{1}/{2}",
new String[]{item.getParent().getFullName(), relativeToParentPath, s},
file)
container.add(new FileContent("items/{0}/{1}", new String[]{relativeToRoot.toString(), s}, file)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void generateFreestyleBundleDefaultsAndCheckContent() throws Exception {
SupportPlugin.class,
j.createWebClient());

String itemEntryPrefix = "items/testFolder/testFreestyle";
String itemEntryPrefix = "items/testFolder/jobs/testFreestyle";
assertNotNull(z.getEntry("manifest.md"));
assertNotNull(z.getEntry(itemEntryPrefix + "/config.xml"));
assertNotNull(z.getEntry(itemEntryPrefix + "/nextBuildNumber"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void generateBundleDefaultsAndCheckContent() throws Exception {
SupportPlugin.class,
j.createWebClient());

String buildsEntryPrefix = "items/testFolder/testFreestyle/builds/" + fBuild.number;
String buildsEntryPrefix = "items/testFolder/jobs/testFreestyle/builds/" + fBuild.number;
assertNotNull(z.getEntry("manifest.md"));
assertNotNull(z.getEntry(buildsEntryPrefix + "/build.xml"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void addContentsFromFreestyle() throws Exception {

Map<String, String> output = SupportTestUtils.invokeComponentToMap(new AbstractItemDirectoryComponent(), p);

String prefix = "items/" + FOLDER_NAME + "/" + JOB_NAME;
String prefix = "items/" + FOLDER_NAME + "/jobs/" + JOB_NAME;
assertTrue(output.containsKey(prefix + "/config.xml"));
assertTrue(output.containsKey(prefix + "/builds/1/build.xml"));
assertTrue(output.containsKey(prefix + "/builds/1/log"));
Expand All @@ -159,7 +159,7 @@ public void addContentsFromPipeline() throws Exception {

Map<String, String> output = SupportTestUtils.invokeComponentToMap(new AbstractItemDirectoryComponent(), p);

String prefix = "items/" + FOLDER_NAME + "/" + JOB_NAME;
String prefix = "items/" + FOLDER_NAME + "/jobs/" + JOB_NAME;
assertTrue(output.containsKey(prefix + "/config.xml"));
assertTrue(output.containsKey(prefix + "/nextBuildNumber"));
assertTrue(output.containsKey(prefix + "/builds/1/build.xml"));
Expand Down

0 comments on commit cbf1261

Please sign in to comment.