/* (non-Javadoc) * @see javax.tools.JavaFileManager#getJavaFileForInput(javax.tools.JavaFileManager.Location, java.lang.String, javax.tools.JavaFileObject.Kind) */ @Override public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException { if (kind != Kind.CLASS && kind != Kind.SOURCE) { throw new IllegalArgumentException("Invalid kind : " + kind); // $NON-NLS-1$ } Iterable<? extends File> files = getLocation(location); if (files == null) { throw new IllegalArgumentException("Unknown location : " + location); // $NON-NLS-1$ } String normalizedFileName = normalized(className); normalizedFileName += kind.extension; for (File file : files) { if (file.isDirectory()) { // handle directory File f = new File(file, normalizedFileName); if (f.exists()) { return new EclipseFileObject(className, f.toURI(), kind, this.charset); } else { continue; // go to next entry in the location } } else if (isArchive(file)) { // handle archive file Archive archive = getArchive(file); if (archive != Archive.UNKNOWN_ARCHIVE) { if (archive.contains(normalizedFileName)) { return archive.getArchiveFileObject(normalizedFileName, this.charset); } } } } return null; }
public static void load(Archive a) { Buffer fragmentsenc = new Buffer(a.get("fragmentsenc.txt")); Buffer badenc = new Buffer(a.get("badenc.txt")); Buffer domainenc = new Buffer(a.get("domainenc.txt")); Buffer tldlist = new Buffer(a.get("tldlist.txt")); unpack(fragmentsenc, badenc, domainenc, tldlist); }
@Test public void flagsArePropagated() throws Exception { BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()); BuildTarget target = BuildTargetFactory.newInstance("//foo:bar"); BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build(); Archive archive = Archive.from( target, params, new SourcePathResolver(resolver), DEFAULT_ARCHIVER, ImmutableList.of("-foo"), DEFAULT_RANLIB, ImmutableList.of("-bar"), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of(new FakeSourcePath("simple.o"))); ImmutableList<Step> steps = archive.getBuildSteps(FakeBuildContext.NOOP_CONTEXT, new FakeBuildableContext()); Step archiveStep = FluentIterable.from(steps).filter(ArchiveStep.class).first().get(); assertThat( archiveStep.getDescription(TestExecutionContext.newInstance()), containsString("-foo")); Step ranlibStep = FluentIterable.from(steps).filter(RanlibStep.class).first().get(); assertThat( ranlibStep.getDescription(TestExecutionContext.newInstance()), containsString("-bar")); }
@Test public void testThatOriginalBuildParamsDepsDoNotPropagateToArchive() { SourcePathResolver pathResolver = new SourcePathResolver(new BuildRuleResolver()); // Create an `Archive` rule using build params with an existing dependency, // as if coming from a `TargetNode` which had declared deps. These should *not* // propagate to the `Archive` rule, since it only cares about dependencies generating // it's immediate inputs. BuildRule dep = new FakeBuildRule( BuildRuleParamsFactory.createTrivialBuildRuleParams( BuildTargetFactory.newInstance("//:fake")), pathResolver); BuildTarget target = BuildTargetFactory.newInstance("//:archive"); BuildRuleParams params = new FakeBuildRuleParamsBuilder(BuildTargetFactory.newInstance("//:dummy")) .setDeps(ImmutableSortedSet.of(dep)) .build(); Archive archive = Archives.createArchiveRule( pathResolver, target, params, DEFAULT_ARCHIVER, DEFAULT_OUTPUT, DEFAULT_INPUTS); // Verify that the archive rules dependencies are empty. assertEquals(archive.getDeps(), ImmutableSortedSet.<BuildRule>of()); }
@Test public void testThatBuildTargetSourcePathDepsAndPathsArePropagated() { BuildRuleResolver resolver = new BuildRuleResolver(); BuildTarget target = BuildTargetFactory.newInstance("//foo:bar"); BuildRuleParams params = BuildRuleParamsFactory.createTrivialBuildRuleParams(target); // Create a couple of genrules to generate inputs for an archive rule. Genrule genrule1 = (Genrule) GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")) .setOut("foo/bar.o") .build(resolver); Genrule genrule2 = (Genrule) GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule2")) .setOut("foo/test.o") .build(resolver); // Build the archive using a normal input the outputs of the genrules above. Archive archive = Archives.createArchiveRule( new SourcePathResolver(resolver), target, params, DEFAULT_ARCHIVER, DEFAULT_OUTPUT, ImmutableList.<SourcePath>of( new TestSourcePath("simple.o"), new BuildTargetSourcePath(genrule1.getBuildTarget()), new BuildTargetSourcePath(genrule2.getBuildTarget()))); // Verify that the archive dependencies include the genrules providing the // SourcePath inputs. assertEquals(ImmutableSortedSet.<BuildRule>of(genrule1, genrule2), archive.getDeps()); }
/* (non-Javadoc) * @see javax.tools.JavaFileManager#getFileForInput(javax.tools.JavaFileManager.Location, java.lang.String, java.lang.String) */ @Override public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException { Iterable<? extends File> files = getLocation(location); if (files == null) { throw new IllegalArgumentException("Unknown location : " + location); // $NON-NLS-1$ } String normalizedFileName = normalized(packageName) + '/' + relativeName.replace('\\', '/'); for (File file : files) { if (file.isDirectory()) { // handle directory File f = new File(file, normalizedFileName); if (f.exists()) { return new EclipseFileObject( packageName + File.separator + relativeName, f.toURI(), getKind(f), this.charset); } else { continue; // go to next entry in the location } } else if (isArchive(file)) { // handle archive file Archive archive = getArchive(file); if (archive != Archive.UNKNOWN_ARCHIVE) { if (archive.contains(normalizedFileName)) { return archive.getArchiveFileObject(normalizedFileName, this.charset); } } } } return null; }
/* (non-Javadoc) * @see javax.tools.JavaFileManager#close() */ @Override public void close() throws IOException { if (this.locations != null) this.locations.clear(); for (Archive archive : this.archivesCache.values()) { archive.close(); } this.archivesCache.clear(); }
/** * Returns whether the {@link Package} has at least one {@link Archive} compatible with the host * platform. */ public boolean hasCompatibleArchive() { for (Archive archive : mArchives) { if (archive.isCompatible()) { return true; } } return false; }
@Override public boolean contains(File item) { for (Archive<File> archive : archives) { if (archive.contains(item)) { return true; } } return false; }
@Override public boolean add(File item) { // Add to archive one by one, until one is successful or archives are exhausted. for (Archive<File> archive : archives) { if (archive.add(item)) { return true; } } return false; }
@Override public boolean remove(File item) { // Remove on every archive, returning true if at least one was successful boolean success = false; for (Archive<File> archive : archives) { if (archive.remove(item)) { success = true; } } return success; }
@Override public File[] getAll() { // Merge files from all archives, ignoring duplicates Set<File> fileSet = new HashSet<File>(); for (Archive<File> archive : archives) { fileSet.addAll(Arrays.asList(archive.getAll())); } File[] files = new File[fileSet.size()]; fileSet.toArray(files); return files; }
@SuppressWarnings("unchecked") public Map<String, Object> getInnerData(Map<String, Object> context) { if (context instanceof Map<?, ?> && ((Map<String, Object>) context).containsKey("$$archive") && ((Map<String, Object>) context).containsKey("$$id")) { Map<String, Object> datumAsMap = (Map<String, Object>) context; Archive arch = jsonContext.getArchive((String) datumAsMap.get("$$archive")); if (arch == null) return null; Object target = arch.getObject((Integer) datumAsMap.get("$$id")); if (target instanceof Map<?, ?>) return (Map<String, Object>) target; } return null; }
/** @see Command */ public void execute() { results = new ArrayList(); validatateXml(); if (isValidateNested()) { List archives = archive.getArchiveFiles(); for (int i = 0; i < archives.size(); i++) { Archive a = (Archive) archives.get(i); if (!a.isModuleFile()) continue; ModuleFile m = (ModuleFile) a; ValidateXmlCommand cmd = new ValidateXmlCommand(m); cmd.execute(); results.addAll(cmd.getResult()); } } }
@Authenticated(value = {LoggedIn.class, HasRole.class}) @Authorized(value = "admin") @Transactional(readOnly = true) @AddCSRFToken public Result createArchive(long parentArchiveId) throws ArchiveNotFoundException { ArchiveUpsertForm archiveUpsertData = new ArchiveUpsertForm(); if (parentArchiveId != 0) { Archive archive = archiveService.findArchiveById(parentArchiveId); archiveUpsertData.parentJid = archive.getJid(); } Form<ArchiveUpsertForm> archiveUpsertForm = Form.form(ArchiveUpsertForm.class).fill(archiveUpsertData); return showCreateArchive(parentArchiveId, archiveUpsertForm); }
/** * Return certificates for signed bundle, otherwise null. * * @return An array of certificates or null. */ public ArrayList getCertificateChains(boolean onlyTrusted) { if (checkCerts) { Certificate[] c = archive.getCertificates(); checkCerts = false; if (c != null) { ArrayList failed = new ArrayList(); untrustedCerts = Util.getCertificateChains(c, failed); if (!failed.isEmpty()) { // NYI, log Bundle archive has invalid certificates untrustedCerts = null; } } } ArrayList res = trustedCerts; if (!onlyTrusted && untrustedCerts != null) { if (res == null) { res = untrustedCerts; } else { res = new ArrayList(trustedCerts.size() + untrustedCerts.size()); res.addAll(trustedCerts); res.addAll(untrustedCerts); } } return res; }
@Override public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { String clsName = name.replaceAll("\\.", "/"); ClassNode node = (ClassNode) archive.get(clsName); if (node != null) { modify(node); byte[] clsData = archive.getEntry(clsName); if (clsData != null) { Class<?> cls = defineClass(name, clsData, 0, clsData.length, domain); if (resolve) resolveClass(cls); return cls; } } return super.findSystemClass(name); }
/** Deletes the archive files. */ void removeArchiveFiles() { for (ArchiveFile link : archive.getArchiveFiles()) { link.deleteFile(removeAfterExtractionAction); if (isRemoveDownloadLinksAfterExtraction()) { link.deleteLink(); } } }
@Authenticated(value = {LoggedIn.class, HasRole.class}) @Authorized(value = "admin") @Transactional(readOnly = true) @AddCSRFToken public Result editArchive(long archiveId) throws ArchiveNotFoundException { Archive archive = archiveService.findArchiveById(archiveId); ArchiveUpsertForm archiveUpsertData = new ArchiveUpsertForm(); if (archive.getParentArchive() != null) { archiveUpsertData.parentJid = archive.getParentArchive().getJid(); } archiveUpsertData.name = archive.getName(); archiveUpsertData.description = archive.getDescription(); Form<ArchiveUpsertForm> archiveUpsertForm = Form.form(ArchiveUpsertForm.class).fill(archiveUpsertData); return showEditArchive(archiveUpsertForm, archive); }
/** Close archive for further access. It should still be possible to get attributes. */ public void close() { if (archives != null) { for (Iterator i = archives.iterator(); i.hasNext(); ) { ((Archive) i.next()).close(); } archives = null; } archive.close(); }
/** * Get a BundleResourceStream to named entry inside a bundle. Leading '/' is stripped. * * @param component Entry to get reference to. * @param ix index of sub archives. A postive number is the classpath entry index. 0 means look in * the main bundle. * @return BundleResourceStream to entry or null if it doesn't exist. */ public BundleResourceStream getBundleResourceStream(String component, int ix) { if (component.startsWith("/")) { component = component.substring(1); } if (ix == 0) { return archive.getBundleResourceStream(component); } else { return ((FileArchive) archives.get(ix - 1)).getBundleResourceStream(component); } }
private Result showEditArchive(Form<ArchiveUpsertForm> archiveUpsertForm, Archive archive) { LazyHtml content = new LazyHtml( editArchiveView.render( archiveUpsertForm, archive.getId(), archiveService .getAllArchives() .stream() .filter(f -> !f.containsJidInHierarchy(archive.getJid())) .collect(Collectors.toList()))); ArchiveControllerUtils.appendUpdateLayout(content, archive); JerahmeelControllerUtils.getInstance().appendSidebarLayout(content); ArchiveControllerUtils.appendBreadcrumbsLayout( content, new InternalLink( Messages.get("archive.edit"), routes.ArchiveController.editArchive(archive.getId()))); JerahmeelControllerUtils.getInstance().appendTemplateLayout(content, "Archive - Edit"); return JerahmeelControllerUtils.getInstance().lazyOk(content); }
@BeforeClass public static void findDependencies() throws Exception { Path path = Paths.get("target/classes"); Archive archive = new Archive(path, ClassFileReader.newInstance(path)) {}; Finder finder = Dependencies.getClassDependencyFinder(); archive .reader() .getClassFiles() .forEach( classFile -> StreamSupport.stream(finder.findDependencies(classFile).spliterator(), false) .filter(dependency -> !isAnnotation(dependency)) .filter(dependency -> !self(dependency)) .forEach( dependency -> packageDependencies .computeIfAbsent( dependency.getOrigin().getPackageName(), key -> new TreeSet<>()) .add(dependency.getTarget().getPackageName()))); }
public static void load(Archive archive) { Buffer stream = new Buffer(archive.decompressFile("varp.dat")); anInt702 = 0; int cacheSize = stream.getUnsignedLEShort(); if (cache == null) cache = new Varp[cacheSize]; if (anIntArray703 == null) anIntArray703 = new int[cacheSize]; for (int j = 0; j < cacheSize; j++) { if (cache[j] == null) cache[j] = new Varp(); cache[j].readValues(stream, j); } if (stream.position != stream.buffer.length) System.out.println("varptype load mismatch"); }
@Test public void testThatBuildTargetSourcePathDepsAndPathsArePropagated() throws Exception { BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()); BuildTarget target = BuildTargetFactory.newInstance("//foo:bar"); BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build(); // Create a couple of genrules to generate inputs for an archive rule. Genrule genrule1 = (Genrule) GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule")) .setOut("foo/bar.o") .build(resolver); Genrule genrule2 = (Genrule) GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule2")) .setOut("foo/test.o") .build(resolver); // Build the archive using a normal input the outputs of the genrules above. Archive archive = Archive.from( target, params, new SourcePathResolver(resolver), DEFAULT_ARCHIVER, ImmutableList.of(), DEFAULT_RANLIB, ImmutableList.of(), Archive.Contents.NORMAL, DEFAULT_OUTPUT, ImmutableList.of( new FakeSourcePath("simple.o"), new BuildTargetSourcePath(genrule1.getBuildTarget()), new BuildTargetSourcePath(genrule2.getBuildTarget()))); // Verify that the archive dependencies include the genrules providing the // SourcePath inputs. assertEquals(ImmutableSortedSet.<BuildRule>of(genrule1, genrule2), archive.getDeps()); }
public ActionForward generate( ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { ExecutionCourse executionCourse = getExecutionCourse(request); if (executionCourse == null) { return mapping.findForward("fallback"); } ArchiveOptions options = getOptions(request); if (options == null) { return prepare(mapping, actionForm, request, response); } String name = getArchiveName(executionCourse); // NOTE: Using a DiskZipArchive instead of a ZipArchive because a // ZipArchive // writes directly to the response during the entire process and // prevents // the server from showing an error page when something goes wrong. This // leaves the user with a corrupt Zip file and no other information. Archive archive = new DiskZipArchive(response, name); Fetcher fetcher = new Fetcher(archive, request, response); queueResources(request, executionCourse, options, fetcher); List<Content> contents = new ArrayList<Content>(); contents.add(MetaDomainObject.getMeta(ExecutionCourseSite.class).getAssociatedPortal()); contents.add(executionCourse.getSite()); FilterFunctionalityContext context = new FilterFunctionalityContext(request, contents); fetcher.process(context); archive.finish(); return null; }
/** Performs the dependency analysis on the given archives. */ public void run(List<Archive> archives) { // build a map from Location to Archive for (Archive archive : archives) { for (Location l : archive.getClasses()) { if (!map.containsKey(l)) { map.put(l, archive); } else { // duplicated class warning? } } } // traverse and analyze all dependencies for (Archive archive : archives) { ArchiveDeps deps; if (type == Type.CLASS || type == Type.VERBOSE) { deps = new ClassVisitor(archive); } else { deps = new PackageVisitor(archive); } archive.visitDependences(deps); results.put(archive, deps); } }
/** * Remove bundle archive from persistent storage. If we removed the active revision also remove * bundle status files. */ public void purge() { close(); if (storage.removeArchive(this)) { (new File(bundleDir, LOCATION_FILE)).delete(); (new File(bundleDir, AUTOSTART_FILE)).delete(); (new File(bundleDir, REV_FILE)).delete(); (new File(bundleDir, STARTLEVEL_FILE)).delete(); (new File(bundleDir, LAST_MODIFIED_FILE)).delete(); } archive.purge(); if (bundleDir.list().length == 0) { bundleDir.delete(); } }
public void start(Archive streamLoader, Client client1) { String as[] = {"model_version", "anim_version", "midi_version", "map_version"}; for (int i = 0; i < 4; i++) { byte abyte0[] = streamLoader.decompressFile(as[i]); int j = abyte0.length / 2; Buffer stream = new Buffer(abyte0); versions[i] = new int[j]; filePriorities[i] = new byte[j]; for (int l = 0; l < j; l++) versions[i][l] = stream.getUnsignedLEShort(); } String as1[] = {"model_crc", "anim_crc", "midi_crc", "map_crc"}; for (int k = 0; k < 4; k++) { byte abyte1[] = streamLoader.decompressFile(as1[k]); int i1 = abyte1.length / 4; Buffer stream_1 = new Buffer(abyte1); crcs[k] = new int[i1]; for (int l1 = 0; l1 < i1; l1++) crcs[k][l1] = stream_1.getInt(); } byte abyte2[] = streamLoader.decompressFile("model_index"); int j1 = versions[0].length; modelIndices = new byte[j1]; for (int k1 = 0; k1 < j1; k1++) if (k1 < abyte2.length) modelIndices[k1] = abyte2[k1]; else modelIndices[k1] = 0; abyte2 = streamLoader.decompressFile("map_index"); Buffer stream2 = new Buffer(abyte2); j1 = abyte2.length / 7; mapIndices1 = new int[j1]; mapIndices2 = new int[j1]; mapIndices3 = new int[j1]; mapIndices4 = new int[j1]; for (int i2 = 0; i2 < j1; i2++) { mapIndices1[i2] = stream2.getUnsignedLEShort(); mapIndices2[i2] = stream2.getUnsignedLEShort(); mapIndices3[i2] = stream2.getUnsignedLEShort(); mapIndices4[i2] = stream2.getUnsignedByte(); } abyte2 = streamLoader.decompressFile("anim_index"); stream2 = new Buffer(abyte2); j1 = abyte2.length / 2; anIntArray1360 = new int[j1]; for (int j2 = 0; j2 < j1; j2++) anIntArray1360[j2] = stream2.getUnsignedLEShort(); abyte2 = streamLoader.decompressFile("midi_index"); stream2 = new Buffer(abyte2); j1 = abyte2.length; anIntArray1348 = new int[j1]; for (int k2 = 0; k2 < j1; k2++) anIntArray1348[k2] = stream2.getUnsignedByte(); clientInstance = client1; running = true; clientInstance.startRunnable(this, 2); }
@Authenticated(value = {LoggedIn.class, HasRole.class}) @Authorized(value = "admin") @Transactional @RequireCSRFCheck public Result postEditArchive(long archiveId) throws ArchiveNotFoundException { Archive archive = archiveService.findArchiveById(archiveId); Form<ArchiveUpsertForm> archiveUpsertForm = Form.form(ArchiveUpsertForm.class).bindFromRequest(); if (formHasErrors(archiveUpsertForm)) { return showEditArchive(archiveUpsertForm, archive); } ArchiveUpsertForm archiveUpsertData = archiveUpsertForm.get(); archiveService.updateArchive( archive.getJid(), archiveUpsertData.parentJid, archiveUpsertData.name, archiveUpsertData.description, IdentityUtils.getUserJid(), IdentityUtils.getIpAddress()); return redirect(routes.ArchiveController.viewArchives(archive.getId())); }