public static File getBundledCourseRoot(final String courseName, Class clazz) { @NonNls String jarPath = PathUtil.getJarPathForClass(clazz); if (jarPath.endsWith(".jar")) { final File jarFile = new File(jarPath); File pluginBaseDir = jarFile.getParentFile(); File coursesDir = new File(pluginBaseDir, "courses"); if (!coursesDir.exists()) { if (!coursesDir.mkdir()) { LOG.info("Failed to create courses dir"); return coursesDir; } } try { ZipUtil.extract(jarFile, pluginBaseDir, (dir, name) -> name.equals(courseName)); } catch (IOException e) { LOG.info("Failed to extract default course", e); } return coursesDir; } return new File(jarPath, "courses"); }
@NotNull public List<File> getClassRoots(Element libraryElement, @Nullable ModuleSettingsImpl moduleSettings) { List<File> files = new ArrayList<File>(); //todo[nik] support jar directories final Element classesChild = libraryElement.getChild("CLASSES"); if (classesChild != null) { final List<Element> roots = JDOMUtil.getChildren(classesChild, "root"); final ExpandMacroToPathMap pathMap = createExpandMacroMap(moduleSettings); for (Element root : roots) { final String url = root.getAttributeValue("url"); final String path = VfsUtilCore.urlToPath(url); files.add(new File(PathUtil.getLocalPath(pathMap.substitute(path, true)))); } } return files; }
public void testDeleteOverwritingFiles() { final String firstFile = createFile("d1/xxx.txt", "1"); final String secondFile = createFile("d2/xxx.txt", "2"); final JpsArtifact a = addArtifact("a", root().dir("ddd").dirCopy(PathUtil.getParentPath(firstFile)).parentDirCopy(secondFile).fileCopy(createFile("y.txt")) ); buildAll(); assertOutput(a, fs().dir("ddd").file("xxx.txt", "1").file("y.txt")); delete(firstFile); buildAll(); assertDeletedAndCopied("out/artifacts/a/ddd/xxx.txt", "d2/xxx.txt"); assertOutput(a, fs().dir("ddd").file("xxx.txt", "2").file("y.txt")); buildAllAndAssertUpToDate(); delete(secondFile); buildAll(); assertDeleted("out/artifacts/a/ddd/xxx.txt"); assertOutput(a, fs().dir("ddd").file("y.txt")); }
public void testTwoDirsInArchive() { final String dir1 = PathUtil.getParentPath(PathUtil.getParentPath(createFile("dir1/a/x.txt"))); final String dir2 = PathUtil.getParentPath(PathUtil.getParentPath(createFile("dir2/a/y.txt"))); final JpsArtifact a = addArtifact( root() .archive("a.jar") .dirCopy(dir1) .dirCopy(dir2) .dir("a").fileCopy(createFile("z.txt")) ); buildAll(); assertOutput(a, fs() .archive("a.jar") .dir("a") .file("x.txt") .file("y.txt") .file("z.txt") ); }
/** * @return Android SDK download URL */ @NotNull public static String getSdkDownloadUrl() { String url = System.getProperty("android.sdkurl"); if (!StringUtil.isEmptyOrSpaces(url)) { File file = new File(url); if (file.isFile()) { // Can't use any path => URL utilities as they don't add two slashes // after the protocol as required by IJ downloader return LocalFileSystem.PROTOCOL_PREFIX + PathUtil.toSystemIndependentName(file.getAbsolutePath()); } else { System.err.println("File " + file.getAbsolutePath() + " does not exist."); } } String downloadUrl = AndroidSdkUtils.getSdkDownloadUrl(); if (downloadUrl == null) { throw new IllegalStateException("Unsupported OS"); } return downloadUrl; }
@Nullable private static TargetIdeInfo getGoTestTarget(Project project, String path) { WorkspacePath targetPackage = WorkspacePath.createIfValid(PathUtil.getParentPath(path)); if (targetPackage == null) { return null; } TargetName targetName = TargetName.createIfValid(PathUtil.getFileName(path)); if (targetName == null) { return null; } Label label = Label.create(targetPackage, targetName); BlazeProjectData projectData = BlazeProjectDataManager.getInstance(project).getBlazeProjectData(); if (projectData == null) { return null; } TargetIdeInfo target = projectData.targetMap.get(TargetKey.forPlainTarget(label)); if (target != null && target.kind.languageClass.equals(LanguageClass.GO) && target.kind.ruleType.equals(RuleType.TEST)) { return target; } return null; }
public void testMoveClassAndDelete() { String a1 = createFile("src1/A.java", "class A{}"); String b = createFile("src2/B.java", "class B{}"); JpsModule m = addModule("m", PathUtil.getParentPath(a1), PathUtil.getParentPath(b)); makeAll(); assertOutput(m, fs().file("A.class").file("B.class")); delete(a1); String a2 = createFile("src2/A.java", "class A{}"); makeAll(); assertOutput(m, fs().file("A.class").file("B.class")); delete(a2); makeAll(); assertOutput(m, fs().file("B.class")); }
public static boolean isPath(@Nullable String s) { if (!StringUtil.isEmpty(s)) { s = ObjectUtils.assertNotNull(s); s = FileUtil.toSystemIndependentName(s); final List<String> components = StringUtil.split(s, "/"); for (String name : components) { if (name == components.get(0) && SystemInfo.isWindows && name.endsWith(":")) { continue; } if (!PathUtil.isValidFileName(name)) { return false; } } return true; } return false; }
/** * Canonicalizes the label (to the form [@external_workspace]//packagePath:packageRelativeTarget). * Returns null if the string does not represent a valid label. */ @Nullable public static Label createLabelFromString( @Nullable BlazePackage blazePackage, @Nullable String labelString) { if (labelString == null) { return null; } int colonIndex = labelString.indexOf(':'); if (isAbsolute(labelString)) { if (colonIndex == -1) { // add the implicit rule name labelString += ":" + PathUtil.getFileName(labelString); } return Label.createIfValid(labelString); } // package-relative label of the form '[:]relativePath' if (colonIndex > 0 || blazePackage == null) { return null; } Label packageLabel = blazePackage.getPackageLabel(); return packageLabel != null ? packageLabel.withTargetName(labelString.substring(colonIndex + 1)) : null; }
protected void collectListeners(JavaParameters javaParameters, StringBuilder buf, String epName, String delimiter) { final T configuration = getConfiguration(); final Object[] listeners = Extensions.getExtensions(epName); for (final Object listener : listeners) { boolean enabled = true; for (RunConfigurationExtension ext : Extensions.getExtensions(RunConfigurationExtension.EP_NAME)) { if (ext.isListenerDisabled(configuration, listener, getRunnerSettings())) { enabled = false; break; } } if (enabled) { if (buf.length() > 0) buf.append(delimiter); final Class classListener = listener.getClass(); buf.append(classListener.getName()); javaParameters.getClassPath().add(PathUtil.getJarPathForClass(classListener)); } } }
@Override protected void setUp() throws Exception { if (ourOutputRoot == null) { ourOutputRoot = FileUtil.createTempDirectory("ExecutionTestCase", null, true); } myModuleOutputDir = new File(ourOutputRoot, PathUtil.getFileName(getTestAppPath())); myChecker = initOutputChecker(); EdtTestUtil.runInEdtAndWait(new ThrowableRunnable<Throwable>() { @Override public void run() throws Throwable { ExecutionTestCase.super.setUp(); } }); if (!myModuleOutputDir.exists()) { myCompilerTester = new CompilerTester(myProject, Arrays.asList(ModuleManager.getInstance(myProject).getModules())); List<CompilerMessage> messages = myCompilerTester.rebuild(); for (CompilerMessage message : messages) { if (message.getCategory() == CompilerMessageCategory.ERROR) { FileUtil.delete(myModuleOutputDir); fail("Compilation failed: " + message); } } } }
private String getItemText(String relativePath) { if (pathFormat == PathFormat.PackageLocal) { if (containingPackage.length() > relativePath.length()) { return ""; } return StringUtil.trimStart(relativePath.substring(containingPackage.length()), "/"); } String parentPath = PathUtil.getParentPath(relativePath); while (!parentPath.isEmpty()) { if (filePathFragment.startsWith(parentPath + "/")) { return StringUtil.trimStart(relativePath, parentPath + "/"); } else if (filePathFragment.startsWith(parentPath)) { return StringUtil.trimStart(relativePath, parentPath); } parentPath = PathUtil.getParentPath(parentPath); } return relativePath; }
private Set<VirtualFile> getNotExcludedRoots() { Set<VirtualFile> roots = new LinkedHashSet<VirtualFile>(); String[] excludedRootUrls = getLibraryEditor().getExcludedRootUrls(); Set<VirtualFile> excludedRoots = new HashSet<VirtualFile>(); for (String url : excludedRootUrls) { ContainerUtil.addIfNotNull(excludedRoots, VirtualFileManager.getInstance().findFileByUrl(url)); } for (PersistentOrderRootType type : OrderRootType.getAllPersistentTypes()) { VirtualFile[] files = getLibraryEditor().getFiles(type); for (VirtualFile file : files) { if (!VfsUtilCore.isUnder(file, excludedRoots)) { roots.add(PathUtil.getLocalFile(file)); } } } return roots; }
@BeforeMethod public void setUp() throws Exception { JavaTestFixtureFactory.getFixtureFactory(); // registers Java module fixture builder final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory(); final TestFixtureBuilder<IdeaProjectTestFixture> testFixtureBuilder = fixtureFactory.createFixtureBuilder(getClass().getSimpleName()); myFixture = fixtureFactory.createTempDirTestFixture(); myFixture.setUp(); FileUtil.copyDir(new File(PluginPathManager.getPluginHomePath("testng") + "/testData/runConfiguration/module1"), new File(myFixture.getTempDirPath()), false); myProjectFixture = testFixtureBuilder.getFixture(); final JavaModuleFixtureBuilder javaModuleFixtureBuilder = testFixtureBuilder.addModule(JavaModuleFixtureBuilder.class); javaModuleFixtureBuilder.addContentRoot(myFixture.getTempDirPath()).addSourceRoot("src"); javaModuleFixtureBuilder.addLibrary("testng", PathUtil.getJarPathForClass(AfterMethod.class)); myProjectFixture.setUp(); }
@NotNull private VirtualFile createProjectWithSubprojects(Map<String, String> modules, String... nonExistingReferencedModules) throws IOException { Collection<String> customLocationStatements = new LinkedList<String>(); for (Map.Entry<String, String> module : modules.entrySet()) { String path = module.getValue(); if (Strings.isNullOrEmpty(path)) { path = PathUtil.toSystemIndependentName(GradleUtil.getDefaultPhysicalPathFromGradlePath(module.getKey())); } else { customLocationStatements.add(String.format("project('%s').projectDir = new File('%s')", module.getKey(), path)); } createGradleProjectToImport(dir, path); } Iterable<String> allModules = Iterables.concat(modules.keySet(), Iterables.transform(Arrays.asList(nonExistingReferencedModules), pathToModuleName)); return configureTopLevelProject(dir, allModules, customLocationStatements); }
private void addLibraries(Set<Library> libraries, ArtifactRootElement<?> root, CompositePackagingElement<?> archive, List<String> classpath) { PackagingElementFactory factory = PackagingElementFactory.getInstance(); for (Library library : libraries) { if (LibraryPackagingElement.getKindForLibrary(library).containsDirectoriesWithClasses()) { for (VirtualFile classesRoot : library.getFiles(OrderRootType.CLASSES)) { if (classesRoot.isInLocalFileSystem()) { archive.addOrFindChild(factory.createDirectoryCopyWithParentDirectories(classesRoot.getPath(), "/")); } else { final PackagingElement<?> child = factory.createFileCopyWithParentDirectories(PathUtil.getLocalFile(classesRoot).getPath(), "/"); root.addOrFindChild(child); classpath.addAll(ManifestFileUtil.getClasspathForElements(Collections.singletonList(child), myContext, PlainArtifactType.getInstance())); } } } else { final List<? extends PackagingElement<?>> children = factory.createLibraryElements(library); classpath.addAll(ManifestFileUtil.getClasspathForElements(children, myContext, PlainArtifactType.getInstance())); root.addOrFindChildren(children); } } }
@NotNull public static VirtualFile createTemporalFile(@Nullable Project project, @NotNull String prefix, @NotNull String suffix, @NotNull byte[] content) throws IOException { File tempFile = FileUtil.createTempFile(PathUtil.suggestFileName(prefix + "_", true, false), PathUtil.suggestFileName("_" + suffix, true, false), true); if (content.length != 0) { FileUtil.writeToFile(tempFile, content); } VirtualFile file = VfsUtil.findFileByIoFile(tempFile, true); if (file == null) { throw new IOException("Can't create temp file for revision content"); } VfsUtil.markDirtyAndRefresh(true, true, true, file); return file; }
@NotNull @Override public String getPresentableName() { final String name = myLibrary.getName(); if (name != null) { return name; } else { if (myLibrary instanceof LibraryEx && ((LibraryEx)myLibrary).isDisposed()) { return "<unknown>"; } final String[] urls = myLibrary.getUrls(OrderRootType.CLASSES); if (urls.length > 0) { String url = urls[0]; return PathUtil.toPresentableUrl(url); } else { return ProjectBundle.message("library.empty.library.item"); } } }
public static boolean checkTestNGInClasspath(PsiElement psiElement) { final Project project = psiElement.getProject(); final PsiManager manager = PsiManager.getInstance(project); if (JavaPsiFacade.getInstance(manager.getProject()).findClass(TestNG.class.getName(), psiElement.getResolveScope()) == null) { if (!ApplicationManager.getApplication().isUnitTestMode()) { if (Messages.showOkCancelDialog(psiElement.getProject(), "TestNG will be added to module classpath", "Unable to convert.", Messages.getWarningIcon()) != Messages.OK) { return false; } } final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement); if (module == null) return false; String url = VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Assert.class))); ModuleRootModificationUtil.addModuleLibrary(module, url); } return true; }
@Override public boolean browseUsingPath(@Nullable final String url, @Nullable String browserPath, @Nullable final WebBrowser browser, @Nullable final Project project, @NotNull final String[] additionalParameters) { Runnable launchTask = null; if (browserPath == null && browser != null) { browserPath = PathUtil.toSystemDependentName(browser.getPath()); launchTask = new Runnable() { @Override public void run() { browseUsingPath(url, null, browser, project, additionalParameters); } }; } return doLaunch(url, browserPath, browser, project, additionalParameters, launchTask); }
@Override public PsiElement bindToElement(PsiElement element) throws IncorrectOperationException { if (!(element instanceof BuildFile)) { return super.bindToElement(element); } if (element.equals(resolve())) { return myElement; } Label newPackageLabel = ((BuildFile) element).getPackageLabel(); if (newPackageLabel == null) { return myElement; } String newPath = newPackageLabel.blazePackage().toString(); String labelString = myElement.getStringContents(); int colonIndex = labelString.indexOf(':'); if (colonIndex != -1) { return handleRename("//" + newPath + labelString.substring(colonIndex)); } // need to assume there's an implicit rule name return handleRename("//" + newPath + ":" + PathUtil.getFileName(labelString)); }
@NotNull @Override public VirtualFile copyFile(@NotNull final VirtualFile file, @NotNull final String targetPath) { final String path = PathUtil.getParentPath(targetPath); return ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() { @Override public VirtualFile compute() { try { VirtualFile targetDir = findOrCreateDir(path); final String newName = PathUtil.getFileName(targetPath); final VirtualFile existing = targetDir.findChild(newName); if (existing != null) { existing.setBinaryContent(file.contentsToByteArray()); return existing; } return VfsUtilCore.copyFile(this, file, targetDir, newName); } catch (IOException e) { throw new RuntimeException(e); } } }); }
@Override @NotNull public VirtualFile createFile(@NotNull String targetPath) { final String path = PathUtil.getParentPath(targetPath); final String name = PathUtil.getFileName(targetPath); return ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() { @Override public VirtualFile compute() { try { VirtualFile targetDir = findOrCreateDir(path); return targetDir.createChildData(this, name); } catch (IOException e) { throw new RuntimeException(e); } } }); }
public static String getStorageRoot(String[] urls, Project project) { if (urls.length == 0) { return null; } final String localRepositoryPath = FileUtil.toSystemIndependentName(MavenProjectsManager.getInstance(project).getLocalRepository().getPath()); List<String> roots = JBIterable.of(urls).transform(new Function<String, String>() { @Override public String fun(String urlWithPrefix) { String url = StringUtil.trimStart(urlWithPrefix, JarFileSystem.PROTOCOL_PREFIX); return url.startsWith(localRepositoryPath) ? null : FileUtil.toSystemDependentName(PathUtil.getParentPath(url)); } }).toList(); Map<String, Integer> counts = new HashMap<String, Integer>(); for (String root : roots) { int count = counts.get(root) != null ? counts.get(root) : 0; counts.put(root, count + 1); } return Collections.max(counts.entrySet(), new Comparator<Map.Entry<String, Integer>>() { @Override public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) { return o1.getValue().compareTo(o2.getValue()); } }).getKey(); }
@NotNull public final String getFilePath() { String chosenExtension = this.getExtension(); String filename = PathUtil.toSystemIndependentName(this.getFileName()); String extension = PhpNameUtil.getExtension(filename); String fullFileName = chosenExtension.equals(extension)?filename:PhpNameUtil.getFullFileName(filename, chosenExtension); String relativePath = this.myDirectoryCombobox.getRelativePath(); return StringUtil.isEmpty(relativePath)?fullFileName:relativePath + "/" + StringUtil.trimEnd(fullFileName, "/"); }
private String getProjectCreationRootPreviewPath() { String sketchDirectoryName = PathUtil.getFileName(projectRootDirectoryBrowser.getText()); if (importIntoDefaultProjectOption.isSelected()) { return Paths.get(ProjectUtil.getBaseDir(), sketchDirectoryName).toString(); } else if (createProjectInSelectedRootOption.isSelected()) { return projectRootDirectoryBrowser.getText(); } else if (importProjectIntoCustomRootOption.isSelected()) { return Paths.get(customImportRootDirectoryBrowser.getText(), sketchDirectoryName).toString(); } return ""; }
@Override public void run() { logger.info("Preparing to write a total of " + sketchFiles.size() + " to the project package " + packageFqn + "."); for (PsiFile sketchFile : sketchFiles) { logger.info("Writing the sketch PSI file '" + sketchFile.getName() + "' to the project package '" + packageFqn + "'."); String sketchFileExtension = PathUtil.getFileExtension(sketchFile.getName()); if (sketchFileExtension == null || ! sketchFileExtension.equals(JavaFileType.DEFAULT_EXTENSION)) { String generatedSketchFileName = PathUtil.makeFileName(PathUtil.getFileName(sketchFile.getName()), JavaFileType.DEFAULT_EXTENSION); sketchFile.setName(generatedSketchFileName); } WriteCommandAction.Simple<String> command = new WriteCommandAction.Simple<String>(project, sketchFile) { @Override protected void run() throws Throwable { CodeStyleManager.getInstance(project).reformat(sketchFile, false); packageFqn.add(sketchFile); } }; RunResult<String> result = command.execute(); logger.debug("Result of executing the file write action is: '" + result.getResultObject() + "'."); } }
public void reset(CommonProgramRunConfigurationParameters configuration) { setProgramParameters(configuration.getProgramParameters()); setWorkingDirectory(PathUtil.toSystemDependentName(configuration.getWorkingDirectory())); myEnvVariablesComponent.setEnvs(configuration.getEnvs()); myEnvVariablesComponent.setPassParentEnvs(configuration.isPassParentEnvs()); }
public void testFileOrder() { final String firstFile = createFile("d1/xxx.txt", "first"); final String secondFile = createFile("d2/xxx.txt", "second"); final String fooFile = createFile("d3/xxx.txt", "foo"); final JpsArtifact a = addArtifact( root().dir("ddd") .dirCopy(PathUtil.getParentPath(firstFile)) .dirCopy(PathUtil.getParentPath(fooFile)).parentDirCopy(secondFile).end() ); buildAll(); assertOutput(a, fs().dir("ddd").file("xxx.txt", "first")); buildAllAndAssertUpToDate(); change(firstFile, "first2"); buildAll(); assertDeletedAndCopied("out/artifacts/a/ddd/xxx.txt", "d1/xxx.txt"); assertOutput(a, fs().dir("ddd").file("xxx.txt", "first2")); buildAllAndAssertUpToDate(); change(secondFile); buildAllAndAssertUpToDate(); change(fooFile); buildAllAndAssertUpToDate(); delete(fooFile); buildAllAndAssertUpToDate(); delete(secondFile); buildAllAndAssertUpToDate(); }
public void testAddRoot() { String dir1 = PathUtil.getParentPath(createFile("dir1/a.txt", "a")); String dir2 = PathUtil.getParentPath(createFile("dir2/b.txt", "b")); JpsArtifact a = addArtifact(root().dirCopy(dir1)); buildAll(); assertOutput(a, fs().file("a.txt", "a")); a.getRootElement().addChild(JpsPackagingElementFactory.getInstance().createDirectoryCopy(dir2)); buildAll(); assertOutput(a, fs().file("a.txt", "a").file("b.txt", "b")); assertDeletedAndCopied("out/artifacts/a/a.txt", "dir1/a.txt", "dir2/b.txt"); buildAllAndAssertUpToDate(); }
public void testChangeOutput() { String file = createFile("dir/a.txt"); JpsArtifact a = addArtifact(root().parentDirCopy(file)); buildAll(); String oldOutput = a.getOutputPath(); assertNotNull(oldOutput); assertOutput(oldOutput, fs().file("a.txt")); String newOutput = PathUtil.getParentPath(oldOutput) + "/a2"; a.setOutputPath(newOutput); buildAll(); assertOutput(newOutput, fs().file("a.txt")); assertOutput(oldOutput, fs()); buildAllAndAssertUpToDate(); }
@Nullable @Override protected ValidationInfo doValidate() { for (String fileName : myComponent.getFileNamesToCreate()) { if (!PathUtil.isValidFileName(fileName)) { return new ValidationInfo(String.format("File name for properties file '%s' is invalid", fileName)); } else { if (myDirectory.findFile(fileName) != null) { return new ValidationInfo(String.format("File with name '%s' already exist", fileName)); } } } return null; }
@Nullable @Override protected GenfilesPath parseItem(ProjectViewParser parser, ParseContext parseContext) { String canonicalPath = PathUtil.getCanonicalPath(parseContext.current().text); List<BlazeValidationError> errors = new ArrayList<>(); if (!GenfilesPath.validate(canonicalPath, errors)) { parseContext.addErrors(errors); return null; } return new GenfilesPath(canonicalPath); }
public void testModuleOutput() { final String file = createFile("src/A.java", "public class A {}"); final JpsModule module = addModule("a", PathUtil.getParentPath(file)); final JpsArtifact artifact = addArtifact(root().module(module)); buildArtifacts(artifact); assertOutput(artifact, fs().file("A.class")); }
public void testIgnoredFileInArchive() { final String file = createFile("a/.svn/a.txt"); createFile("a/svn/b.txt"); final JpsArtifact a = addArtifact(archive("a.jar").parentDirCopy(PathUtil.getParentPath(file))); buildAll(); assertOutput(a, fs().archive("a.jar").dir("svn").file("b.txt")); }
public void testCopyExcludedFolder() { //explicitly added excluded files should be copied (e.g. compile output) final String file = createFile("xxx/excluded/a.txt"); createFile("xxx/excluded/CVS"); final String excluded = PathUtil.getParentPath(file); final String dir = PathUtil.getParentPath(excluded); final JpsModule module = addModule("myModule"); module.getContentRootsList().addUrl(JpsPathUtil.pathToUrl(dir)); module.getExcludeRootsList().addUrl(JpsPathUtil.pathToUrl(excluded)); final JpsArtifact a = addArtifact(root().dirCopy(excluded)); buildAll(); assertOutput(a, fs().file("a.txt")); }
public void testCopyExcludedFile() { //excluded files under non-excluded directory should not be copied final String file = createFile("xxx/excluded/a.txt"); createFile("xxx/b.txt"); createFile("xxx/CVS"); final String dir = PathUtil.getParentPath(PathUtil.getParentPath(file)); JpsModule module = addModule("myModule"); module.getContentRootsList().addUrl(JpsPathUtil.pathToUrl(dir)); module.getExcludeRootsList().addUrl(JpsPathUtil.pathToUrl(PathUtil.getParentPath(file))); final JpsArtifact a = addArtifact(root().dirCopy(dir)); buildAll(); assertOutput(a, fs().file("b.txt")); }
public void testExtractDirectoryFromExcludedJar() throws IOException { String jarPath = createFile("dir/lib/j.jar"); FileUtil.copy(new File(getJUnitJarPath()), new File(jarPath)); JpsModule module = addModule("m"); String libDir = PathUtil.getParentPath(jarPath); module.getContentRootsList().addUrl(JpsPathUtil.pathToUrl(PathUtil.getParentPath(libDir))); module.getExcludeRootsList().addUrl(JpsPathUtil.pathToUrl(libDir)); final JpsArtifact a = addArtifact("a", root().extractedDir(jarPath, "/junit/textui/")); buildAll(); assertOutput(a, fs().file("ResultPrinter.class") .file("TestRunner.class")); }
@Nullable private File resolveParentDirectory(WorkspacePath packagePath, TargetName targetName) { File packageFile = resolvePackage(packagePath); if (packageFile == null) { return null; } String rulePathParent = PathUtil.getParentPath(targetName.toString()); return new File(packageFile, rulePathParent); }
@Override public void generateTasksForArtifact(Artifact artifact, boolean preprocessing, ArtifactAntGenerationContext context, CompositeGenerator generator) { final ArtifactPropertiesProvider provider; if (preprocessing) { provider = AntArtifactPreProcessingPropertiesProvider.getInstance(); } else { provider = AntArtifactPostprocessingPropertiesProvider.getInstance(); } final AntArtifactProperties properties = (AntArtifactProperties)artifact.getProperties(provider); if (properties != null && properties.isEnabled()) { final String path = VfsUtil.urlToPath(properties.getFileUrl()); String fileName = PathUtil.getFileName(path); String dirPath = PathUtil.getParentPath(path); final String relativePath = GenerationUtils.toRelativePath(dirPath, BuildProperties.getProjectBaseDir(context.getProject()), BuildProperties.getProjectBaseDirProperty(), context.getGenerationOptions()); final Tag ant = new Tag("ant", Pair.create("antfile", fileName), Pair.create("target", properties.getTargetName()), Pair.create("dir", relativePath)); final String outputPath = BuildProperties.propertyRef(context.getArtifactOutputProperty(artifact)); ant.add(new Property(JpsAntArtifactExtensionImpl.ARTIFACT_OUTPUT_PATH_PROPERTY, outputPath)); for (BuildFileProperty property : properties.getUserProperties()) { ant.add(new Property(property.getPropertyName(), property.getPropertyValue())); } generator.add(ant); } }