/** * Unpack a jar file in the given location to a directory. * * @param jarLocation Location containing the jar file * @param destinationFolder Directory to expand into * @return The {@code destinationFolder} * @throws IOException If failed to expand the jar */ public static File unJar(Location jarLocation, File destinationFolder) throws IOException { Preconditions.checkArgument(jarLocation != null); return unJar(Locations.newInputSupplier(jarLocation), destinationFolder); }
@Override public SeekableInputStream call() throws Exception { return Locations.newInputSupplier(location).getInput(); } });
/** * Adds a artifact Jar present at the given {@link Location} to allow Plugin Instantiator to load the class * * @param artifactLocation Location of the Artifact JAR * @param destArtifact {@link ArtifactId} of the plugin * @throws IOException if failed to copy the artifact JAR */ public void addArtifact(Location artifactLocation, ArtifactId destArtifact) throws IOException { File destFile = new File(pluginDir, Artifacts.getFileName(destArtifact)); Files.copy(Locations.newInputSupplier(artifactLocation), destFile); }
/** * Adds a artifact Jar present at the given {@link Location} to allow Plugin Instantiator to load the class * * @param artifactLocation Location of the Artifact JAR * @param destArtifact {@link ArtifactId} of the plugin * @throws IOException if failed to copy the artifact JAR */ public void addArtifact(Location artifactLocation, ArtifactId destArtifact) throws IOException { File destFile = new File(pluginDir, Artifacts.getFileName(destArtifact)); Files.copy(Locations.newInputSupplier(artifactLocation), destFile); }
/** * Creates a temp copy of the program jar. * * @return a new {@link Location} which contains the same content as the program jar */ private Location copyProgramJar(Location targetDir) throws IOException { Location programJarCopy = targetDir.append("program.jar"); ByteStreams.copy(Locations.newInputSupplier(programJarLocation), Locations.newOutputSupplier(programJarCopy)); LOG.debug("Copied Program Jar to {}, source: {}", programJarCopy, programJarLocation); return programJarCopy; }
/** * Load the manifest inside the given jar. * * @param jarLocation Location of the jar file. * @return The manifest inside the jar file or {@code null} if no manifest inside the jar file. * @throws IOException if failed to load the manifest. */ @Nullable public static Manifest getManifest(Location jarLocation) throws IOException { return getManifest(jarLocation.toURI(), Locations.newInputSupplier(jarLocation)); }
private void addArtifact(ArtifactId artifactId, Location jar) throws Exception { File destination = new File(tmpDir, String.format("%s-%s.jar", artifactId.getArtifact(), artifactId.getVersion())); Files.copy(Locations.newInputSupplier(jar), destination); jar.delete(); artifactRepository.addArtifact(Id.Artifact.fromEntityId(artifactId), destination); Preconditions.checkState(destination.delete()); } }
private void addArtifact(ArtifactId artifactId, Location jar) throws Exception { File destination = new File(tmpDir, String.format("%s-%s.jar", artifactId.getArtifact(), artifactId.getVersion())); Files.copy(Locations.newInputSupplier(jar), destination); jar.delete(); artifactRepository.addArtifact(Id.Artifact.fromEntityId(artifactId), destination); Preconditions.checkState(destination.delete()); } }
private File createPluginJar(ArtifactId artifactId, Class<?> pluginClass, Class<?>... pluginClasses) throws IOException { Manifest manifest = createManifest(pluginClass, pluginClasses); Location appJar = PluginJarHelper.createPluginJar(locationFactory, manifest, pluginClass, pluginClasses); File destination = new File(tmpDir, String.format("%s-%s.jar", artifactId.getArtifact(), artifactId.getVersion())); Files.copy(Locations.newInputSupplier(appJar), destination); appJar.delete(); return destination; }
private File createPluginJar(ArtifactId artifactId, Class<?> pluginClass, Class<?>... pluginClasses) throws IOException { Manifest manifest = createManifest(pluginClass, pluginClasses); Location appJar = PluginJarHelper.createPluginJar(locationFactory, manifest, pluginClass, pluginClasses); File destination = new File(tmpDir, String.format("%s-%s.jar", artifactId.getArtifact(), artifactId.getVersion())); Files.copy(Locations.newInputSupplier(appJar), destination); appJar.delete(); return destination; }
protected File buildAppArtifact(Class<?> cls, Manifest manifest, File destination) throws IOException { Location appJar = AppJarHelper.createDeploymentJar(locationFactory, cls, manifest); Files.copy(Locations.newInputSupplier(appJar), destination); return destination; }
private StreamPositionTransformFileReader(StreamFileOffset offset) throws IOException { this.reader = StreamDataFileReader.createWithOffset(Locations.newInputSupplier(offset.getEventLocation()), Locations.newInputSupplier(offset.getIndexLocation()), offset.getOffset()); this.offset = new StreamFileOffset(offset); this.partitionLocation = Locations.getParent(offset.getEventLocation()); LOG.trace("Stream reader created for {}", offset.getEventLocation()); }
private static void copyArtifacts(File pluginDir, SortedMap<ArtifactDescriptor, Set<PluginClass>> plugins) throws IOException { ArtifactDescriptor descriptor = plugins.firstKey(); Files.copy(Locations.newInputSupplier(descriptor.getLocation()), new File(pluginDir, Artifacts.getFileName(descriptor.getArtifactId()))); }
protected HttpResponse addAppArtifact(Id.Artifact artifactId, Class<?> cls) throws Exception { Location appJar = AppJarHelper.createDeploymentJar(locationFactory, cls, new Manifest()); try { return addArtifact(artifactId, Locations.newInputSupplier(appJar), Collections.emptySet()); } finally { appJar.delete(); } }
private static File createJar(Class<?> cls, File destFile, Manifest manifest) throws IOException { Location deploymentJar = AppJarHelper.createDeploymentJar(new LocalLocationFactory(TMP_FOLDER.newFolder()), cls, manifest); DirUtils.mkdirs(destFile.getParentFile()); Files.copy(Locations.newInputSupplier(deploymentJar), destFile); return destFile; } }
private static File createPluginJar(Class<?> cls, File destFile, Manifest manifest) throws IOException { Location deploymentJar = PluginJarHelper.createPluginJar(new LocalLocationFactory(TMP_FOLDER.newFolder()), manifest, cls); DirUtils.mkdirs(destFile.getParentFile()); Files.copy(Locations.newInputSupplier(deploymentJar), destFile); return destFile; }
private static File createAppJar(Class<?> cls, File destFile, Manifest manifest) throws IOException { Location deploymentJar = AppJarHelper.createDeploymentJar(new LocalLocationFactory(TMP_FOLDER.newFolder()), cls, manifest); DirUtils.mkdirs(destFile.getParentFile()); Files.copy(Locations.newInputSupplier(deploymentJar), destFile); return destFile; } }
private static File createAppJar(Class<?> cls, File destFile, Manifest manifest) throws IOException { Location deploymentJar = AppJarHelper.createDeploymentJar(new LocalLocationFactory(TMP_FOLDER.newFolder()), cls, manifest); DirUtils.mkdirs(destFile.getParentFile()); Files.copy(Locations.newInputSupplier(deploymentJar), destFile); return destFile; }
protected Location createModuleJar(Class moduleClass, Location...bundleEmbeddedJars) throws IOException { LocationFactory lf = new LocalLocationFactory(TMP_FOLDER.newFolder()); File[] embeddedJars = new File[bundleEmbeddedJars.length]; for (int i = 0; i < bundleEmbeddedJars.length; i++) { File file = TMP_FOLDER.newFile(); Files.copy(Locations.newInputSupplier(bundleEmbeddedJars[i]), file); embeddedJars[i] = file; } return AppJarHelper.createDeploymentJar(lf, moduleClass, embeddedJars); }
private List<String> readFromOutput(FileSet fileSet, String relativePath) throws IOException { // small amount of data, so expect all data from just 1 file Location location = fileSet.getLocation(relativePath).append("part-m-00000"); return CharStreams.readLines(CharStreams.newReaderSupplier(Locations.newInputSupplier(location), Charsets.UTF_8)); }