org.springframework.boot.loader.archive.Archive Java Examples
The following examples show how to use
org.springframework.boot.loader.archive.Archive.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DependencyProcessor.java From spring-cloud-formula with Apache License 2.0 | 6 votes |
private void processIncludes(List<Archive> archives, List<Action> actions) { if (CollectionUtils.isEmpty(properties.getIncludes())) { return; } List<Dependency> includes = properties.getIncludes(); includes.forEach(include -> { boolean replaced = replaceDependency(include, true, archives, actions); if (!replaced) { return; } // process dependencies Archive includeArchive = findArchive(frameworkArchives, include); List<Dependency> deps = findDependencyInfo(include, includeArchive); deps.forEach(dep -> replaceDependency(dep, true, archives, actions)); }); }
Example #2
Source File: DependencyProcessor.java From spring-cloud-formula with Apache License 2.0 | 6 votes |
private void processSubstitutions(List<Archive> archives, List<Action> actions) { if (CollectionUtils.isEmpty(properties.getSubstitutions())) { return; } List<Dependency> substitutions = properties.getSubstitutions(); substitutions.forEach(substitution -> { boolean replaced = replaceDependency(substitution, false, archives, actions); if (!replaced) { return; } // process dependencies Archive origin = findArchive(frameworkArchives, substitution); List<Dependency> deps = findDependencyInfo(substitution, origin); deps.forEach(dep -> replaceDependency(dep, true, archives, actions)); }); }
Example #3
Source File: BootApplicationConfigurationMetadataResolver.java From spring-cloud-dataflow with Apache License 2.0 | 6 votes |
/** * Return metadata about configuration properties that are documented via <a href= * "https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html"> * Spring Boot configuration metadata</a> and visible in an app. * * @param app a Spring Cloud Stream app; typically a Boot uberjar, but directories are * supported as well */ @Override public List<ConfigurationMetadataProperty> listProperties(Resource app, boolean exhaustive) { try { if (app != null) { if (isDockerSchema(app.getURI())) { return resolvePropertiesFromContainerImage(app.getURI()); } else { Archive archive = resolveAsArchive(app); return listProperties(archive, exhaustive); } } } catch (Exception e) { logger.warn("Failed to retrieve properties for resource:" + app, e); return Collections.emptyList(); } return Collections.emptyList(); }
Example #4
Source File: DependencyProcessor.java From spring-cloud-formula with Apache License 2.0 | 6 votes |
private List<Dependency> findDependencyInfo(Dependency dependency, Archive archive) { Predicate<LauncherProperties.DependencyInfo> predicate = dependencyInfo -> dependency.getArtifactId().equals(dependencyInfo.getArtifact().getArtifactId()); if (dependency.getVersion() == null) { predicate.and(info -> { String url = archive.toString(); return url.contains("/" + info.getArtifact().getArtifactId() + "-" + info.getArtifact().getVersion()); }); } else { predicate.and(info -> dependency.getVersion().equals(info.getArtifact().getVersion())); } return properties.getDependencyInfos().stream() .filter(predicate) .map(LauncherProperties.DependencyInfo::getDependencies).findFirst().orElseGet(() -> { logger.warn("dependencies info not found, return empty collection, dependency={}, archive={}", dependency, archive); return new ArrayList<>(); }); }
Example #5
Source File: FormulaLauncher.java From spring-cloud-formula with Apache License 2.0 | 6 votes |
private void setSystemProperties(List<Action> actions, List<Archive> archives) { // actions for (int i = 0; i < actions.size(); i++) { Action action = actions.get(i); System.setProperty("formula.launcher.actions[" + i + "].type", action.getType().name()); System.setProperty("formula.launcher.actions[" + i + "].archive", action.getArchive()); if (action.getOldArchive() != null) { System.setProperty("formula.launcher.actions[" + i + "].old-archive", action.getOldArchive()); } } // archives for (int i = 0; i < archives.size(); i++) { Archive archive = archives.get(i); System.setProperty("formula.launcher.archives[" + i + "]", archive.toString()); } }
Example #6
Source File: WebApplication.java From TrackRay with GNU General Public License v3.0 | 6 votes |
protected static Archive createArchive(Class clazz) throws Exception { ProtectionDomain protectionDomain = clazz.getProtectionDomain(); CodeSource codeSource = protectionDomain.getCodeSource(); URI location = codeSource != null ? codeSource.getLocation().toURI() : null; String path = location != null ? location.getSchemeSpecificPart() : null; if (path == null) { throw new IllegalStateException("Unable to determine code source archive"); } else { File root = new File(path); if (!root.exists()) { throw new IllegalStateException("Unable to determine code source archive from " + root); } else { return (Archive)(root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root)); } } }
Example #7
Source File: LancherTest.java From tac with MIT License | 6 votes |
protected final Archive createArchive() throws Exception { ProtectionDomain protectionDomain = getClass().getProtectionDomain(); CodeSource codeSource = protectionDomain.getCodeSource(); URI location = (codeSource == null ? null : codeSource.getLocation().toURI()); String path = (location == null ? null : location.getSchemeSpecificPart()); if (path == null) { throw new IllegalStateException("Unable to determine code source archive"); } File root = new File(path); if (!root.exists()) { throw new IllegalStateException( "Unable to determine code source archive from " + root); } return (root.isDirectory() ? new ExplodedArchive(root) : new JarFileArchive(root)); }
Example #8
Source File: LancherTest.java From tac with MIT License | 5 votes |
protected boolean isNestedArchive(Archive.Entry entry) { System.out.println(entry.getName()); if (entry.isDirectory()) { return entry.getName().equals(BOOT_INF_CLASSES); } return entry.getName().startsWith(BOOT_INF_LIB); }
Example #9
Source File: ConfigurationMetadataDocumentationMojo.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Override public List<Archive> getNestedArchives(EntryFilter ignored) throws IOException { try { List<Archive> archives = new ArrayList<>(mavenProject.getRuntimeClasspathElements().size()); for (String dep : mavenProject.getRuntimeClasspathElements()) { File file = new File(dep); archives.add(file.isDirectory() ? new ExplodedArchive(file) : new JarFileArchive(file)); } return archives; } catch (DependencyResolutionRequiredException e) { throw new IOException("Could not create boot archive", e); } }
Example #10
Source File: FunctionArchiveDeployer.java From spring-cloud-function with Apache License 2.0 | 5 votes |
private List<Archive> discoverClassPathAcrhives() throws Exception { Iterator<Archive> iter = this.getClassPathArchivesIterator(); List<Archive> classPathArchives = new ArrayList<>(); while (iter.hasNext()) { classPathArchives.add(iter.next()); } if (CollectionUtils.isEmpty(classPathArchives)) { classPathArchives.add(this.getArchive()); } return classPathArchives; }
Example #11
Source File: BootClassLoaderFactory.java From spring-cloud-dashboard with Apache License 2.0 | 5 votes |
public URLClassLoader createClassLoader() { boolean useBoot14Layout = false; for (Archive.Entry entry : archive) { if (entry.getName().startsWith(BOOT_14_LIBS_LOCATION)) { useBoot14Layout = true; break; } } ClassLoaderExposingLauncher launcher = useBoot14Layout ? new Boot14ClassLoaderExposingLauncher() : new Boot13ClassLoaderExposingLauncher(); return launcher.createClassLoader(); }
Example #12
Source File: ProcessLauncherState.java From spring-boot-graal-feature with Apache License 2.0 | 5 votes |
protected String getClasspath(boolean includeTargetClasses) { if (this.classpath == null) { PathResolver resolver = new PathResolver(DependencyResolver.instance()); Archive root = ArchiveUtils.getArchive(ProcessLauncherState.class); List<Archive> resolved = resolver.resolve(root, name, profiles); StringBuilder builder = new StringBuilder(); if (includeTargetClasses) { builder.append(new File("target/classes").getAbsolutePath()); } else { builder.append(new File("target/orm-0.0.1.BUILD-SNAPSHOT.jar") .getAbsolutePath()); } try { for (Archive archive : resolved) { if (archive.getUrl().equals(root.getUrl())) { continue; } if (builder.length() > 0) { builder.append(File.pathSeparator); } builder.append(file(archive.getUrl().toString())); } } catch (MalformedURLException e) { throw new IllegalStateException("Cannot find archive", e); } log.debug("Classpath: " + builder); this.classpath = builder.toString(); } return this.classpath; }
Example #13
Source File: BootApplicationConfigurationMetadataResolver.java From spring-cloud-dashboard with Apache License 2.0 | 5 votes |
/** * Return metadata about configuration properties that are documented via * <a href="http://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html"> * Spring Boot configuration metadata</a> and visible in an app. * @param app a Spring Cloud Stream app; typically a Boot uberjar, * but directories are supported as well */ public List<ConfigurationMetadataProperty> listProperties(Resource app, boolean exhaustive) { try { Archive archive = resolveAsArchive(app); return listProperties(archive, exhaustive); } catch (IOException e) { throw new RuntimeException("Failed to list properties for " + app, e); } }
Example #14
Source File: BootClassLoaderFactory.java From spring-cloud-dataflow with Apache License 2.0 | 5 votes |
public URLClassLoader createClassLoader() { boolean useBoot14Layout = false; for (Archive.Entry entry : archive) { if (entry.getName().startsWith(BOOT_14_LIBS_LOCATION)) { useBoot14Layout = true; break; } } ClassLoaderExposingLauncher launcher = useBoot14Layout ? new Boot14ClassLoaderExposingLauncher() : new Boot13ClassLoaderExposingLauncher(); return launcher.createClassLoader(); }
Example #15
Source File: LancherTest.java From tac with MIT License | 5 votes |
private Archive getUnpackedNestedArchive(JarEntry jarEntry) throws IOException { String name = jarEntry.getName(); if (name.lastIndexOf("/") != -1) { name = name.substring(name.lastIndexOf("/") + 1); } File file = new File(getTempUnpackFolder(), name); if (!file.exists() || file.length() != jarEntry.getSize()) { unpack(jarEntry, file); } return new JarFileArchive(file, file.toURI().toURL()); }
Example #16
Source File: BootJarLaucherUtils.java From tac with MIT License | 5 votes |
/** * * @param jarFile * @param jarEntry * @return * @throws IOException */ private static Archive getUnpackedNestedArchive(JarFile jarFile, JarEntry jarEntry) throws IOException { String name = jarEntry.getName(); if (name.lastIndexOf("/") != -1) { name = name.substring(name.lastIndexOf("/") + 1); } File file = new File(getTempUnpackFolder(), name); if (!file.exists() || file.length() != jarEntry.getSize()) { unpack(jarFile, jarEntry, file); } return new JarFileArchive(file, file.toURI().toURL()); }
Example #17
Source File: FormulaLauncher.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
@Override public boolean isNestedArchive(Archive.Entry entry) { if (entry.isDirectory()) { return entry.getName().equals(BOOT_INF_CLASSES); } return entry.getName().startsWith(BOOT_INF_LIB); }
Example #18
Source File: DependencyProcessor.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
Archive findArchive(List<Archive> archives, Dependency dependency) { String entryName = "META-INF/maven/" + dependency.getGroupId() + "/" + dependency.getArtifactId() + "/pom.xml"; for (Archive archive : archives) { if (StreamSupport.stream(archive.spliterator(), false).anyMatch(entry -> entry.getName().equals(entryName))) { return archive; } } return null; }
Example #19
Source File: DependencyProcessor.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
private boolean same(Archive includeArchive, Archive currentArchive) { if (includeArchive == null || currentArchive == null) { return includeArchive == currentArchive; } String left = includeArchive.toString().replaceFirst("^.*" + FormulaLauncher.BOOT_INF_LIB, ""); String right = currentArchive.toString().replaceFirst("^.*" + FormulaLauncher.BOOT_INF_LIB, ""); return left.equals(right); }
Example #20
Source File: DependencyProcessor.java From spring-cloud-formula with Apache License 2.0 | 5 votes |
private boolean replaceDependency(Dependency dependency, boolean forceAdd, List<Archive> archives, List<Action> actions) { Archive archive = findArchive(frameworkArchives, dependency); if (archive == null) { logger.warn("dependency not found, {}", dependency); return false; } Archive currentArchive = findArchive(archives, dependency); if (same(archive, currentArchive) && !dependency.getGroupId().contains("baidu")) { return false; } if (currentArchive == null && !forceAdd) { return false; } logger.info("adding launcher archive: {}", archive); archives.add(archive); actions.add(Action.builder().type(ActionType.ADD).archive(archive.toString()).build()); if (currentArchive != null) { logger.info("removing launcher archive: {}", currentArchive); archives.remove(currentArchive); } return true; }
Example #21
Source File: BootApplicationConfigurationMetadataResolver.java From spring-cloud-dashboard with Apache License 2.0 | 4 votes |
private Archive resolveAsArchive(Resource app) throws IOException { File moduleFile = app.getFile(); return moduleFile.isDirectory() ? new ExplodedArchive(moduleFile) : new JarFileArchive(moduleFile); }
Example #22
Source File: BootClassLoaderFactory.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
@Override protected void postProcessClassPathArchives(List<Archive> archives) throws Exception { archives.add(0, getArchive()); }
Example #23
Source File: BootClassLoaderFactory.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
@Override protected boolean isNestedArchive(Archive.Entry entry) { return !entry.isDirectory() && entry.getName().startsWith(BOOT_13_LIBS_LOCATION); }
Example #24
Source File: BootClassLoaderFactory.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
@Override protected boolean isNestedArchive(Archive.Entry entry) { return (!entry.isDirectory() && entry.getName().startsWith(BOOT_14_LIBS_LOCATION)) || (entry.isDirectory() && entry.getName().equals(BOOT_14_CLASSESS_LOCATION)); }
Example #25
Source File: BootApplicationConfigurationMetadataResolver.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
private Archive resolveAsArchive(Resource app) throws IOException { File moduleFile = app.getFile(); return moduleFile.isDirectory() ? new ExplodedArchive(moduleFile) : new JarFileArchive(moduleFile); }
Example #26
Source File: BootClassLoaderFactory.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
@Override protected void postProcessClassPathArchives(List<Archive> archives) throws Exception { archives.add(0, getArchive()); }
Example #27
Source File: FunctionArchiveDeployer.java From spring-cloud-function with Apache License 2.0 | 4 votes |
@Override protected ClassLoader createClassLoader(Iterator<Archive> archives) throws Exception { URLClassLoader cl = (URLClassLoader) super.createClassLoader(archives); return this.createClassLoader(cl.getURLs()); }
Example #28
Source File: FunctionArchiveDeployer.java From spring-cloud-function with Apache License 2.0 | 4 votes |
FunctionArchiveDeployer(Archive archive) { super(archive); }
Example #29
Source File: DefaultValidationService.java From spring-cloud-dataflow with Apache License 2.0 | 4 votes |
private static Archive resolveAsArchive(Resource app) throws IOException { Assert.notNull(app, "The resource specified for the app must not be null"); File moduleFile = app.getFile(); return moduleFile.isDirectory() ? new ExplodedArchive(moduleFile) : new JarFileArchive(moduleFile); }
Example #30
Source File: ConfigurationMetadataDocumentationMojo.java From spring-cloud-stream-app-starters with Apache License 2.0 | 4 votes |
@Override public Archive getFilteredArchive(EntryRenameFilter filter) throws IOException { throw new UnsupportedOperationException(); }