Search in sources :

Example 6 with GradleImport

use of com.android.tools.idea.gradle.eclipse.GradleImport in project android by JetBrains.

the class GradleImportTest method testModuleNamesFromDir.

@SuppressWarnings("ResultOfMethodCallIgnored")
public void testModuleNamesFromDir() throws Exception {
    // Regression test for issue where there is no .project file and
    // the project name has to be inferred from the directory name instead
    Pair<File, File> pair = createLibrary2(new File("Library1"));
    File root = pair.getFirst();
    File app = pair.getSecond();
    File propertyFile = new File(app, ".project");
    propertyFile.delete();
    final AtomicReference<GradleImport> importReference = new AtomicReference<>();
    File imported = checkProject(app, "" + MSG_HEADER + MSG_MANIFEST + MSG_UNHANDLED + "* .gitignore\n" + MSG_REPLACED_JARS + "guava-13.0.1.jar => com.google.guava:guava:13.0.1\n" + MSG_GUESSED_VERSIONS + "guava-13.0.1.jar => version 13.0.1 in com.google.guava:guava:13.0.1\n" + MSG_FOLDER_STRUCTURE + "In Library1:\n" + "* src/ => library1/src/main/java/\n" + "In Library2:\n" + "* src/ => library2/src/main/java/\n" + "In AndroidLibrary:\n" + "* AndroidManifest.xml => androidLibrary/src/main/AndroidManifest.xml\n" + "* src/ => androidLibrary/src/main/java/\n" + "In AndroidApp:\n" + "* AndroidManifest.xml => androidApp/src/main/AndroidManifest.xml\n" + "* res/ => androidApp/src/main/res/\n" + "* src/ => androidApp/src/main/java/\n" + MSG_FOOTER, false, /* checkBuild */
    importReference::set);
    deleteDir(root);
    deleteDir(imported);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) GradleImport(com.android.tools.idea.gradle.eclipse.GradleImport) File(java.io.File)

Example 7 with GradleImport

use of com.android.tools.idea.gradle.eclipse.GradleImport in project android by JetBrains.

the class GradleImportTest method testErrorHandling2.

@SuppressWarnings("ResultOfMethodCallIgnored")
public void testErrorHandling2() throws Exception {
    // Broken manifest
    File root = Files.createTempDir();
    // Place project in a deep subdirectory such that it does not leave a broken
    // sibling project for other unit tests to discover as an instrumentation test
    File projectDir = new File(root, "sub1" + separator + "sub2" + separator + "sub3");
    projectDir.mkdirs();
    createProject(projectDir, "testError2", "test.pkg");
    File manifest = new File(projectDir, "AndroidManifest.xml");
    Files.write("" + "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<x>\n", manifest, UTF_8);
    final AtomicReference<GradleImport> importReference = new AtomicReference<>();
    File imported = checkProject(projectDir, "" + MSG_HEADER + "\n" + " * $ROOT/AndroidManifest.xml:\n" + "Invalid XML file: $ROOT/AndroidManifest.xml:\n" + "XML document structures must start and end within the same entity.\n" + MSG_FOOTER, false, /* checkBuild */
    importReference::set);
    assertEquals("[$MANIFEST_FILE:\n" + "Invalid XML file: $MANIFEST_FILE:\n" + "XML document structures must start and end within the same entity.]", importReference.get().getErrors().toString().replace(manifest.getPath(), "$MANIFEST_FILE").replace(manifest.getCanonicalPath(), "$MANIFEST_FILE"));
    deleteDir(root);
    deleteDir(imported);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) GradleImport(com.android.tools.idea.gradle.eclipse.GradleImport) File(java.io.File)

Example 8 with GradleImport

use of com.android.tools.idea.gradle.eclipse.GradleImport in project android by JetBrains.

the class AdtModuleImporter method getGradleImport.

@NotNull
private GradleImport getGradleImport() {
    AdtImportBuilder builder = AdtImportBuilder.getBuilder(myContext);
    assert builder != null;
    GradleImport importer = builder.getImporter();
    assert importer != null;
    return importer;
}
Also used : AdtImportBuilder(com.android.tools.idea.gradle.eclipse.AdtImportBuilder) GradleImport(com.android.tools.idea.gradle.eclipse.GradleImport) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with GradleImport

use of com.android.tools.idea.gradle.eclipse.GradleImport in project android by JetBrains.

the class GradleImportTest method testNoProjectProperties.

@SuppressWarnings("ResultOfMethodCallIgnored")
public void testNoProjectProperties() throws Exception {
    // Missing project.properties
    File projectDir = createProject("testError3", "test.pkg");
    new File(projectDir, FN_PROJECT_PROPERTIES).delete();
    final AtomicReference<GradleImport> importReference = new AtomicReference<>();
    File imported = checkProject(projectDir, "" + MSG_HEADER + MSG_FOLDER_STRUCTURE + DEFAULT_MOVED + MSG_FOOTER, true, /* checkBuild */
    importReference::set);
    deleteDir(projectDir);
    deleteDir(imported);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) GradleImport(com.android.tools.idea.gradle.eclipse.GradleImport) File(java.io.File)

Example 10 with GradleImport

use of com.android.tools.idea.gradle.eclipse.GradleImport in project android by JetBrains.

the class GradleImportTest method testLibrariesWithWorkspaceMapping2.

@SuppressWarnings("ResultOfMethodCallIgnored")
public void testLibrariesWithWorkspaceMapping2() throws Exception {
    // Provide manually edited workspace location; importer reads workspace data
    // to find it
    final String library1Path = "subdir1" + separator + "subdir2" + separator + "UnrelatedName";
    final File library1Dir = new File(library1Path);
    Pair<File, File> pair = createLibrary2(library1Dir);
    final File root = pair.getFirst();
    File app = pair.getSecond();
    final File library1AbsDir = new File(root, library1Path);
    final File workspace = new File(root, "workspace");
    workspace.mkdirs();
    File metadata = new File(workspace, ".metadata");
    metadata.mkdirs();
    new File(metadata, "version.ini").createNewFile();
    assertTrue(isEclipseWorkspaceDir(workspace));
    File projects = new File(metadata, ".plugins" + separator + "org.eclipse.core.resources" + separator + ".projects");
    projects.mkdirs();
    File library1 = new File(projects, "Library1");
    library1.mkdirs();
    File location = new File(library1, ".location");
    byte[] data = ("blahblahblahURI//" + SdkUtils.fileToUrl(library1AbsDir) + "\000blahblahblah").getBytes(UTF_8);
    Files.write(data, location);
    final AtomicReference<GradleImport> importReference = new AtomicReference<>();
    File imported = checkProject(app, "" + MSG_HEADER + MSG_MANIFEST + MSG_UNHANDLED + "* .gitignore\n" + MSG_REPLACED_JARS + "guava-13.0.1.jar => com.google.guava:guava:13.0.1\n" + MSG_GUESSED_VERSIONS + "guava-13.0.1.jar => version 13.0.1 in com.google.guava:guava:13.0.1\n" + MSG_FOLDER_STRUCTURE + "In Library1:\n" + "* src/ => library1/src/main/java/\n" + "In Library2:\n" + "* src/ => library2/src/main/java/\n" + "In AndroidLibrary:\n" + "* AndroidManifest.xml => androidLibrary/src/main/AndroidManifest.xml\n" + "* src/ => androidLibrary/src/main/java/\n" + "In AndroidApp:\n" + "* AndroidManifest.xml => androidApp/src/main/AndroidManifest.xml\n" + "* res/ => androidApp/src/main/res/\n" + "* src/ => androidApp/src/main/java/\n" + MSG_FOOTER, false, /* checkBuild */
    importer -> {
        importReference.set(importer);
        importer.setEclipseWorkspace(workspace);
    });
    assertEquals("{/Library1=" + new File(root, library1Path).getCanonicalPath() + ", /Library2=" + new File(root, "Library2").getCanonicalPath() + "}", describePathMap(importReference.get()));
    deleteDir(root);
    deleteDir(imported);
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) GradleImport(com.android.tools.idea.gradle.eclipse.GradleImport) File(java.io.File)

Aggregations

GradleImport (com.android.tools.idea.gradle.eclipse.GradleImport)15 File (java.io.File)14 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 AdtImportBuilder (com.android.tools.idea.gradle.eclipse.AdtImportBuilder)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 VfsUtil.findFileByIoFile (com.intellij.openapi.vfs.VfsUtil.findFileByIoFile)2 VfsUtilCore.virtualToIoFile (com.intellij.openapi.vfs.VfsUtilCore.virtualToIoFile)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Map (java.util.Map)2 NotNull (org.jetbrains.annotations.NotNull)2 Supplier (com.google.common.base.Supplier)1 Project (com.intellij.openapi.project.Project)1