use of org.jetbrains.jps.model.module.JpsModule in project android by JetBrains.
the class AndroidBuilderTest method test7.
public void test7() throws Exception {
final boolean[] class1Deleted = { false };
final MyExecutor executor = new MyExecutor("com.example.simple") {
@Override
protected void doCheckJar(@NotNull String jarId, @NotNull String jarPath) {
if ("library_package_jar".equals(jarId)) {
File tmpDir = null;
try {
tmpDir = FileUtil.createTempDirectory("library_package_jar_checking", "tmp");
final File jar = new File(tmpDir, "file.jar");
FileUtil.copy(new File(jarPath), jar);
TestFileSystemBuilder fs = TestFileSystemItem.fs().archive("file.jar").dir("lib").file("MyLibClass.class");
if (!class1Deleted[0]) {
fs = fs.file("MyLibClass1.class");
}
assertOutput(tmpDir.getPath(), fs);
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (tmpDir != null) {
FileUtil.delete(tmpDir);
}
}
}
}
};
final JpsSdk<JpsSimpleElement<JpsAndroidSdkProperties>> androidSdk = addJdkAndAndroidSdk();
addPathPatterns(executor, androidSdk);
final JpsModule appModule = addAndroidModule("app", new String[] { "src" }, "app", "app", androidSdk).getFirst();
final JpsModule libModule = addAndroidModule("lib", new String[] { "src" }, "lib", "lib", androidSdk).getFirst();
final JpsAndroidModuleExtension libExtension = AndroidJpsUtil.getExtension(libModule);
assert libExtension != null;
final JpsAndroidModuleProperties libProps = ((JpsAndroidModuleExtensionImpl) libExtension).getProperties();
libProps.PROJECT_TYPE = PROJECT_TYPE_LIBRARY;
rebuildAll();
checkBuildLog(executor, "expected_log");
assertEquals(Collections.singleton("library_package_jar"), executor.getCheckedJars());
checkMakeUpToDate(executor);
appModule.getDependenciesList().addModuleDependency(libModule);
makeAll();
checkBuildLog(executor, "expected_log_1");
assertTrue(executor.getCheckedJars().isEmpty());
checkMakeUpToDate(executor);
change(getProjectPath("lib/src/lib/MyLibClass.java"));
makeAll();
checkBuildLog(executor, "expected_log_2");
assertEquals(Collections.singleton("library_package_jar"), executor.getCheckedJars());
checkMakeUpToDate(executor);
assertTrue(FileUtil.delete(new File(getProjectPath("lib/src/lib/MyLibClass1.java"))));
class1Deleted[0] = true;
makeAll();
checkBuildLog(executor, "expected_log_2");
assertEquals(Collections.singleton("library_package_jar"), executor.getCheckedJars());
checkMakeUpToDate(executor);
assertTrue(FileUtil.delete(new File(getProjectPath("lib/src/lib/MyLibClass.java"))));
makeAll();
checkBuildLog(executor, "expected_log_3");
assertTrue(executor.getCheckedJars().isEmpty());
checkMakeUpToDate(executor);
final JpsLibrary appLib = appModule.addModuleLibrary("appLib", JpsJavaLibraryType.INSTANCE);
appLib.addRoot(getProjectPath("lib/external_jar.jar"), JpsOrderRootType.COMPILED);
appModule.getDependenciesList().addLibraryDependency(appLib);
final JpsLibrary libLib = libModule.addModuleLibrary("libLib", JpsJavaLibraryType.INSTANCE);
libLib.addRoot(new File(getProjectPath("lib/external_jar.jar")), JpsOrderRootType.COMPILED);
libModule.getDependenciesList().addLibraryDependency(libLib);
makeAll().assertSuccessful();
checkBuildLog(executor, "expected_log_4");
assertTrue(executor.getCheckedJars().isEmpty());
checkMakeUpToDate(executor);
}
use of org.jetbrains.jps.model.module.JpsModule in project intellij-elixir by KronicDeth.
the class ElixirTarget method computeDependencies.
public Collection<BuildTarget<?>> computeDependencies() {
List<BuildTarget<?>> dependencies = new ArrayList<BuildTarget<?>>();
Set<JpsModule> modules = JpsJavaExtensionService.dependencies(myModule).includedIn(JpsJavaClasspathKind.compile(isTests())).getModules();
for (JpsModule module : modules) {
if (module.getModuleType().equals(JpsElixirModuleType.INSTANCE)) {
dependencies.add(new ElixirTarget(getElixirTargetType(), module));
}
}
if (isTests()) {
dependencies.add(new ElixirTarget(ElixirTargetType.PRODUCTION, myModule));
}
return dependencies;
}
use of org.jetbrains.jps.model.module.JpsModule in project intellij-elixir by KronicDeth.
the class MixBuilder method build.
@Override
public void build(@NotNull ElixirTarget target, @NotNull DirtyFilesHolder<ElixirSourceRootDescriptor, ElixirTarget> holder, @NotNull BuildOutputConsumer outputConsumer, @NotNull CompileContext context) throws ProjectBuildException, IOException {
if (!holder.hasDirtyFiles() && !holder.hasRemovedFiles())
return;
JpsModule module = target.getModule();
JpsProject project = module.getProject();
ElixirCompilerOptions compilerOptions = JpsElixirCompilerOptionsExtension.getOrCreateExtension(project).getOptions();
if (!compilerOptions.myUseMixCompiler)
return;
String mixPath = getMixExecutablePath(project);
if (mixPath == null) {
String errorMessage = "Mix path is not set.";
context.processMessage(new CompilerMessage(NAME, BuildMessage.Kind.ERROR, errorMessage));
throw new ProjectBuildException(errorMessage);
}
JpsSdk<JpsDummyElement> sdk = ElixirTargetBuilderUtil.getSdk(context, module);
String elixirPath = JpsElixirSdkType.getScriptInterpreterExecutable(sdk.getHomePath()).getAbsolutePath();
for (String contentRootUrl : module.getContentRootsList().getUrls()) {
String contentRootPath = new URL(contentRootUrl).getPath();
File contentRootDir = new File(contentRootPath);
File mixConfigFile = new File(contentRootDir, MIX_CONFIG_FILE_NAME);
if (!mixConfigFile.exists())
continue;
runMix(elixirPath, mixPath, contentRootPath, compilerOptions.myAttachDebugInfoEnabled, context);
}
}
use of org.jetbrains.jps.model.module.JpsModule in project android by JetBrains.
the class AndroidAarDepsBuilder method doBuild.
private static boolean doBuild(final CompileContext context, AndroidAarDepsBuildTarget target, BuildOutputConsumer outputConsumer) {
final JpsModule module = target.getModule();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
if (extension == null || extension.isLibrary()) {
return true;
}
File outputDir = AndroidJpsUtil.getDirectoryForIntermediateArtifacts(context, module);
outputDir = AndroidJpsUtil.createDirIfNotExist(outputDir, context, BUILDER_NAME);
if (outputDir == null) {
return false;
}
final List<String> srcJarFiles = new ArrayList<String>();
for (BuildRootDescriptor descriptor : context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context)) {
final File file = descriptor.getRootFile();
if (file.exists()) {
srcJarFiles.add(file.getPath());
}
}
if (srcJarFiles.size() == 0) {
return true;
}
context.processMessage(new ProgressMessage(AndroidJpsBundle.message("android.jps.progress.aar.dependencies.packaging", module.getName())));
File tempDir = null;
try {
tempDir = FileUtil.createTempDirectory("extracted_aar_deps", "tmp");
for (int i = srcJarFiles.size() - 1; i >= 0; i--) {
ZipUtil.extract(new File(srcJarFiles.get(i)), tempDir, null, true);
}
final File outputJarFile = new File(outputDir, AndroidCommonUtils.AAR_DEPS_JAR_FILE_NAME);
if (!packDirectoryIntoJar(tempDir, outputJarFile, context)) {
return false;
}
final AndroidBuildTestingManager testingManager = AndroidBuildTestingManager.getTestingManager();
if (testingManager != null && outputJarFile.isFile()) {
testingManager.getCommandExecutor().checkJarContent("aar_dependencies_package_jar", outputJarFile.getPath());
}
outputConsumer.registerOutputFile(outputJarFile, srcJarFiles);
return true;
} catch (IOException e) {
AndroidJpsUtil.reportExceptionError(context, null, e, BUILDER_NAME);
return false;
} finally {
if (tempDir != null) {
FileUtil.delete(tempDir);
}
}
}
use of org.jetbrains.jps.model.module.JpsModule in project android by JetBrains.
the class AndroidResourceCachingBuilder method runPngCaching.
private static boolean runPngCaching(AndroidResourceCachingBuildTarget target, CompileContext context, BuildOutputConsumer outputConsumer) throws IOException {
final JpsModule module = target.getModule();
final JpsAndroidModuleExtension extension = AndroidJpsUtil.getExtension(module);
assert extension != null;
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.INFO, AndroidJpsBundle.message("android.jps.progress.res.caching", module.getName())));
final AndroidPlatform platform = AndroidJpsUtil.getAndroidPlatform(module, context, BUILDER_NAME);
if (platform == null) {
return false;
}
final File resCacheDir = target.getOutputDir(context);
// todo: probably it may be done automatically
if (context.getScope().isBuildForced(target) && resCacheDir.exists()) {
if (!FileUtil.delete(resCacheDir)) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", resCacheDir.getPath())));
return false;
}
}
if (!resCacheDir.exists()) {
if (!resCacheDir.mkdirs()) {
context.processMessage(new CompilerMessage(BUILDER_NAME, BuildMessage.Kind.ERROR, AndroidJpsBundle.message("android.jps.cannot.create.directory", resCacheDir.getPath())));
return false;
}
}
final IAndroidTarget androidTarget = platform.getTarget();
final List<BuildRootDescriptor> roots = context.getProjectDescriptor().getBuildRootIndex().getTargetRoots(target, context);
if (roots.size() == 0) {
return true;
}
final List<String> inputDirs = new ArrayList<String>();
for (BuildRootDescriptor root : roots) {
final File f = root.getRootFile();
if (f.exists()) {
inputDirs.add(f.getPath());
}
}
final Map<AndroidCompilerMessageKind, List<String>> messages = AndroidApt.crunch(androidTarget, inputDirs, resCacheDir.getPath());
AndroidJpsUtil.addMessages(context, messages, BUILDER_NAME, module.getName());
final boolean success = messages.get(AndroidCompilerMessageKind.ERROR).isEmpty();
if (success) {
final Map<String, File> outputFiles = new HashMap<String, File>();
FileUtil.processFilesRecursively(resCacheDir, new Processor<File>() {
@Override
public boolean process(File file) {
if (file.isFile()) {
final String relativePath = FileUtil.getRelativePath(resCacheDir, file);
if (relativePath != null) {
outputFiles.put(relativePath, file);
}
}
return true;
}
});
for (Map.Entry<String, File> entry : outputFiles.entrySet()) {
final String relativePath = entry.getKey();
final File outputFile = entry.getValue();
for (String inputDir : inputDirs) {
final File srcFile = new File(inputDir, relativePath);
outputConsumer.registerOutputFile(outputFile, Collections.singletonList(srcFile.getPath()));
}
}
}
return success;
}
Aggregations