Skip to content

Commit

Permalink
Merge pull request #11 from jenkinsci/master
Browse files Browse the repository at this point in the history
Fork Sync: Update from parent repository
  • Loading branch information
ppiorunski authored Jul 29, 2024
2 parents 5480e68 + 0cfd50a commit f5c20ac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
21 changes: 13 additions & 8 deletions src/main/java/org/jenkinsci/plugins/p4/scm/P4SCMFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.perforce.p4java.option.server.GetExtendedFilesOptions;
import com.perforce.p4java.option.server.GetFileContentsOptions;
import edu.umd.cs.findbugs.annotations.NonNull;
import jenkins.model.Jenkins;
import jenkins.scm.api.SCMFile;
import org.jenkinsci.plugins.p4.client.ConnectionHelper;
import org.jenkinsci.plugins.p4.client.NavigateHelper;
Expand All @@ -19,12 +18,15 @@
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.Logger;

public class P4SCMFile extends SCMFile {

private final P4SCMFileSystem fs;
private final boolean isDir;

private static Logger logger = Logger.getLogger(P4SCMFile.class.getName());

public P4SCMFile(P4SCMFileSystem fs) {
this.fs = fs;
this.isDir = true;
Expand Down Expand Up @@ -149,13 +151,16 @@ public InputStream content() throws IOException, InterruptedException {
}
}

private void addJenkinsFilePathToTagAction(ConnectionHelper p4, List<IFileSpec> file) throws IOException, InterruptedException {
Jenkins j = Jenkins.getInstanceOrNull();
String rootPath = j.getRootDir().getCanonicalPath();
IClient currentClient = p4.getConnection().getCurrentClient();
currentClient.setRoot(rootPath);
List<IFileSpec> where = currentClient.localWhere(file);
fs.addJenkinsFilePath(where.get(0).getDepotPathString());
private void addJenkinsFilePathToTagAction(ConnectionHelper p4, List<IFileSpec> file) {
try {
IClient currentClient = p4.getConnection().getCurrentClient();
currentClient.refresh();
List<IFileSpec> where = currentClient.localWhere(file);
fs.addJenkinsFilePath(where.get(0).getDepotPathString());
} catch (Exception e) {
logger.warning("P4: Error retrieving depot path for the Jenkins file.");
}

}

private List<IFileSpec> getFileSpec() {
Expand Down
14 changes: 9 additions & 5 deletions src/main/java/org/jenkinsci/plugins/p4/scm/P4SCMFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected P4SCMFileSystem(@NonNull Item owner, @NonNull PerforceScm scm, @CheckF
this.p4 = new TempClientHelper(owner, credential, null, ws);
}

public void addJenkinsFilePath(String path) throws IOException, InterruptedException {
public void addJenkinsFilePath(String path) {
if (_job == null || _job.getLastBuild() == null) {
return;
}
Expand All @@ -61,10 +61,14 @@ public void addJenkinsFilePath(String path) throws IOException, InterruptedExcep
return;
}
if (StringUtils.isNotEmpty(definition.getScriptPath()) && definition.isLightweight()) {
Run<?, ?> build = _job.getLastBuild();
TagAction tag = new TagAction(build, credential);
tag.setJenkinsPath(path);
build.addAction(tag);
try {
Run<?, ?> build = _job.getLastBuild();
TagAction tag = new TagAction(build, credential);
tag.setJenkinsPath(path);
build.addAction(tag);
} catch (IOException | InterruptedException e) {
logger.warning("P4: Failed to create temporary TagAction for JENKINSFILE_PATH.");
}
}
}

Expand Down

0 comments on commit f5c20ac

Please sign in to comment.