Skip to content

Commit

Permalink
Merge branch 'master' into update-forms
Browse files Browse the repository at this point in the history
  • Loading branch information
janfaracik committed Nov 10, 2021
2 parents b051f4f + cee0d06 commit 1298ce9
Show file tree
Hide file tree
Showing 96 changed files with 975 additions and 628 deletions.
10 changes: 0 additions & 10 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,6 @@ THE SOFTWARE.
<groupId>com.github.jnr</groupId>
<artifactId>jnr-posix</artifactId>
</dependency>
<!--
For compatibility only; not included into the BOM for the same reason. TODO once
https://github.com/jenkinsci/scm-api-plugin/pull/88 is widely adopted, this
dependency can be dropped.
-->
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>asm5</artifactId>
<version>5.0.1</version>
</dependency>
<dependency>
<groupId>org.kohsuke.stapler</groupId>
<artifactId>stapler</artifactId>
Expand Down
22 changes: 11 additions & 11 deletions core/src/main/java/hudson/ClassicPluginStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ public void startPlugin(PluginWrapper plugin) throws Exception {
public void updateDependency(PluginWrapper depender, PluginWrapper dependee) {
DependencyClassLoader classLoader = findAncestorDependencyClassLoader(depender.classLoader);
if (classLoader != null) {
classLoader.updateTransientDependencies();
classLoader.updateTransitiveDependencies();
LOGGER.log(Level.INFO, "Updated dependency of {0}", depender.getShortName());
}
}
Expand Down Expand Up @@ -580,9 +580,9 @@ static final class DependencyClassLoader extends ClassLoader {
private final PluginManager pluginManager;

/**
* Topologically sorted list of transient dependencies. Lazily initialized via double-checked locking.
* Topologically sorted list of transitive dependencies. Lazily initialized via double-checked locking.
*/
private volatile List<PluginWrapper> transientDependencies;
private volatile List<PluginWrapper> transitiveDependencies;

static {
registerAsParallelCapable();
Expand All @@ -595,17 +595,17 @@ static final class DependencyClassLoader extends ClassLoader {
this.pluginManager = pluginManager;
}

private void updateTransientDependencies() {
private void updateTransitiveDependencies() {
// This will be recalculated at the next time.
transientDependencies = null;
transitiveDependencies = null;
}

private List<PluginWrapper> getTransitiveDependencies() {
List<PluginWrapper> localTransientDependencies = transientDependencies;
if (localTransientDependencies == null) {
List<PluginWrapper> localTransitiveDependencies = transitiveDependencies;
if (localTransitiveDependencies == null) {
synchronized (this) {
localTransientDependencies = transientDependencies;
if (localTransientDependencies == null) {
localTransitiveDependencies = transitiveDependencies;
if (localTransitiveDependencies == null) {
CyclicGraphDetector<PluginWrapper> cgd = new CyclicGraphDetector<PluginWrapper>() {
@Override
protected List<PluginWrapper> getEdges(PluginWrapper pw) {
Expand All @@ -629,11 +629,11 @@ protected List<PluginWrapper> getEdges(PluginWrapper pw) {
throw new AssertionError(e); // such error should have been reported earlier
}

transientDependencies = localTransientDependencies = cgd.getSorted();
transitiveDependencies = localTransitiveDependencies = cgd.getSorted();
}
}
}
return localTransientDependencies;
return localTransitiveDependencies;
}

@Override
Expand Down
5 changes: 2 additions & 3 deletions core/src/main/java/hudson/FilePath.java
Original file line number Diff line number Diff line change
Expand Up @@ -2831,14 +2831,13 @@ private static Integer writeToTar(File baseDir, DirScanner scanner, OutputStream
* Supports large files > 10 GB since 1.627 when this was migrated to use commons-compress.
*/
private static void readFromTar(String name, File baseDir, InputStream in) throws IOException {
baseDir = baseDir.getCanonicalFile();

// TarInputStream t = new TarInputStream(in);
try (TarArchiveInputStream t = new TarArchiveInputStream(in)) {
TarArchiveEntry te;
while ((te = t.getNextTarEntry()) != null) {
File f = new File(baseDir, te.getName()).getCanonicalFile();
if (!f.toPath().startsWith(baseDir.toPath())) {
File f = new File(baseDir, te.getName());
if (!f.toPath().normalize().startsWith(baseDir.toPath())) {
throw new IOException(
"Tar " + name + " contains illegal file name that breaks out of the target directory: " + te.getName());
}
Expand Down
85 changes: 80 additions & 5 deletions core/src/main/java/hudson/PluginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLConnection;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -1734,6 +1735,51 @@ public HttpResponse doProxyConfigure(StaplerRequest req) throws IOException, Ser
return new HttpRedirect("advanced");
}

interface PluginCopier {
void copy(File target) throws Exception;
void cleanup();
}

class FileUploadPluginCopier implements PluginCopier {
private FileItem fileItem;

FileUploadPluginCopier(FileItem fileItem) {
this.fileItem = fileItem;
}

@Override
public void copy(File target) throws Exception {
fileItem.write(target);
}

@Override
public void cleanup() {
fileItem.delete();
}
}

class UrlPluginCopier implements PluginCopier {
private String url;

UrlPluginCopier(String url) {
this.url = url;
}

@Override
public void copy(File target) throws Exception {
try(InputStream input = ProxyConfiguration.getInputStream(new URL(url))) {
Files.copy(input, target.toPath());
} catch(Exception e) {
throw e;
}
}

@Override
public void cleanup() {

}
}

/**
* Uploads a plugin.
*/
Expand All @@ -1742,11 +1788,21 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
try {
Jenkins.get().checkPermission(Jenkins.ADMINISTER);

String fileName = "";
PluginCopier copier;
ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory());
List<FileItem> items = upload.parseRequest(req);
if(StringUtils.isNotBlank(items.get(1).getString())) {
// this is a URL deployment
fileName = items.get(1).getString();
copier = new UrlPluginCopier(fileName);
} else {
// this is a file upload
FileItem fileItem = items.get(0);
fileName = Util.getFileName(fileItem.getName());
copier = new FileUploadPluginCopier(fileItem);
}

// Parse the request
FileItem fileItem = upload.parseRequest(req).get(0);
String fileName = Util.getFileName(fileItem.getName());
if("".equals(fileName)){
return new HttpRedirect("advanced");
}
Expand All @@ -1762,12 +1818,12 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
// TODO Remove this workaround after FILEUPLOAD-293 is resolved.
t.delete();

fileItem.write(t);
copier.copy(t);
} catch (Exception e) {
// Exception thrown is too generic so at least limit the scope where it can occur
throw new ServletException(e);
}
fileItem.delete();
copier.cleanup();

final String baseName = identifyPluginShortName(t);

Expand Down Expand Up @@ -1810,6 +1866,25 @@ public HttpResponse doUploadPlugin(StaplerRequest req) throws IOException, Servl
}
}

@Restricted(NoExternalUse.class)
@RequirePOST public FormValidation doCheckPluginUrl(StaplerRequest request, @QueryParameter String value) throws IOException {
if(StringUtils.isNotBlank(value)) {
try {
URL url = new URL(value);
if(!url.getProtocol().startsWith("http")) {
return FormValidation.error(Messages.PluginManager_invalidUrl());
}

if(!url.getProtocol().equals("https")) {
return FormValidation.warning(Messages.PluginManager_insecureUrl());
}
} catch(MalformedURLException e) {
return FormValidation.error(e.getMessage());
}
}
return FormValidation.ok();
}

@Restricted(NoExternalUse.class)
@RequirePOST public HttpResponse doCheckUpdatesServer() throws IOException {
Jenkins.get().checkPermission(Jenkins.SYSTEM_READ);
Expand Down
6 changes: 6 additions & 0 deletions core/src/main/java/hudson/model/AbstractBuild.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ public AbstractBuild<?,?> getRootBuild() {
return this;
}

@Override
public Queue.Executable getParentExecutable() {
AbstractBuild<?, ?> rootBuild = getRootBuild();
return rootBuild != this ? rootBuild : null;
}

/**
* Used to render the side panel "Back to project" link.
*
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/java/hudson/model/Computer.java
Original file line number Diff line number Diff line change
Expand Up @@ -1807,11 +1807,4 @@ public long getWhen() {
private static final @Deprecated Permission CLOUD_PROVISION = Cloud.PROVISION;

private static final Logger LOGGER = Logger.getLogger(Computer.class.getName());

static {
IconSet.icons.addIcon(new Icon("icon-computer-user-offline icon-sm", "16x16/computer-user-offline.png", Icon.ICON_SMALL_STYLE));
IconSet.icons.addIcon(new Icon("icon-computer-user-offline icon-md", "24x24/computer-user-offline.png", Icon.ICON_MEDIUM_STYLE));
IconSet.icons.addIcon(new Icon("icon-computer-user-offline icon-lg", "32x32/computer-user-offline.png", Icon.ICON_LARGE_STYLE));
IconSet.icons.addIcon(new Icon("icon-computer-user-offline icon-xlg", "48x48/computer-user-offline.png", Icon.ICON_XLARGE_STYLE));
}
}
34 changes: 1 addition & 33 deletions core/src/main/java/hudson/util/TextFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
*/
package hudson.util;

import edu.umd.cs.findbugs.annotations.CreatesObligation;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Util;
import java.io.BufferedReader;
Expand All @@ -38,7 +37,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.stream.Stream;
import jenkins.util.io.LinesStream;

/**
* Represents a text file.
Expand Down Expand Up @@ -79,20 +77,6 @@ public String read() throws IOException {
return out.toString();
}

/**
* @throws RuntimeException in the case of {@link IOException} in {@link #linesStream()}
* @deprecated This method does not properly propagate errors and may lead to file descriptor leaks
* if the collection is not fully iterated. Use {@link #lines2()} instead.
*/
@Deprecated
public @NonNull Iterable<String> lines() {
try {
return linesStream();
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}

/**
* Read all lines from the file as a {@link Stream}. Bytes from the file are decoded into
* characters using the {@link StandardCharsets#UTF_8 UTF-8} {@link Charset charset}. If timely
Expand All @@ -104,26 +88,10 @@ public String read() throws IOException {
* @throws IOException if an I/O error occurs opening the file
*/
@NonNull
public Stream<String> lines2() throws IOException {
public Stream<String> lines() throws IOException {
return Files.lines(Util.fileToPath(file));
}

/**
* Creates a new {@link jenkins.util.io.LinesStream} of the file.
* <p>
* Note: The caller is responsible for closing the returned
* {@code LinesStream}.
* @throws IOException if the file cannot be converted to a
* {@link java.nio.file.Path} or if the file cannot be opened for reading
* @since 2.111
* @deprecated use {@link #lines2}
*/
@CreatesObligation
@Deprecated
public @NonNull LinesStream linesStream() throws IOException {
return new LinesStream(Util.fileToPath(file));
}

/**
* Overwrites the file by the given string.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected ConfigDirectory(File file) {
}

@Override
public synchronized void load() {
public synchronized void load2() {
COL result = create();

if (dir.exists()) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/jenkins/security/s2m/ConfigFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public synchronized void load2() throws IOException {
COL result = create();

if (exists()) {
try (Stream<String> stream = lines2()) {
try (Stream<String> stream = lines()) {
stream.forEach(line -> {
if (line.startsWith("#")) return; // comment
T r = parse(line);
Expand Down
Loading

0 comments on commit 1298ce9

Please sign in to comment.