private DirectoryResource getServicesDirectory(ResourceFacet resourcesFacet) {
   DirectoryResource servicesDirectory =
       resourcesFacet.getResourceFolder().getChildDirectory(SERVICES_DIRECTORY);
   if (!servicesDirectory.exists()) {
     servicesDirectory.mkdirs();
   }
   return servicesDirectory;
 }
Esempio n. 2
0
 public List<File> searchForAllResources(ResourcesEnum resources) {
   this.resources = new ArrayList<File>();
   this.searchString = resources.toString();
   DirectoryResource root = project.getProjectRoot();
   File[] files = root.getUnderlyingResourceObject().listFiles();
   iterateFiles(files);
   return this.resources;
 }
 @Override
 public boolean install() {
   if (!this.isInstalled()) {
     for (DirectoryResource folder : this.getResourceFolders()) {
       folder.mkdirs();
     }
   }
   return true;
 }
Esempio n. 4
0
 @Test
 public void testCreateTopLevelPackage() throws Exception {
   initializeJavaProject();
   DirectoryResource root = getProject().getProjectRoot();
   Resource<?> srcMainJavaDirectory = root.getChild("/src/main/java");
   assertNotNull(srcMainJavaDirectory.reify(DirectoryResource.class));
   Resource<?> testDirectory = srcMainJavaDirectory.getChild("com/test");
   assertNotNull(testDirectory.reify(DirectoryResource.class));
 }
 /**
  * Retrieves the package portion of the current directory if it is a package, null otherwise.
  *
  * @return String representation of the current package, or null
  */
 private String getPackagePortionOfCurrentDirectory() {
   for (DirectoryResource r : project.getFacet(JavaSourceFacet.class).getSourceFolders()) {
     final DirectoryResource currentDirectory = shell.getCurrentDirectory();
     if (ResourceUtil.isChildOf(r, currentDirectory)) {
       // Have to remember to include the last slash so it's not part of the package
       return currentDirectory
           .getFullyQualifiedName()
           .replace(r.getFullyQualifiedName() + "/", "")
           .replaceAll("/", ".");
     }
   }
   return null;
 }
Esempio n. 6
0
  @Override
  public FileResource<?> getConfigFile() {
    DirectoryResource webRoot = project.getFacet(WebResourceFacet.class).getWebRootDirectory();
    FileResource<?> child =
        (FileResource<?>) webRoot.getChild("WEB-INF" + File.separator + "faces-config.xml");

    if (!child.exists()) {
      return new UnknownFileResource(
          child.getResourceFactory(), child.getUnderlyingResourceObject()) {
        @Override
        public InputStream getResourceInputStream() {
          if (!exists()) {
            String projectName = project.getFacet(MetadataFacet.class).getProjectName();
            WebAppDescriptor unit =
                Descriptors.create(WebAppDescriptor.class)
                    .displayName(projectName)
                    .sessionTimeout(30);
            return Streams.fromString(unit.exportAsString());
          } else {
            return super.getResourceInputStream();
          }
        }

        @Override
        public UnknownFileResource setContents(InputStream data) {
          if (!exists()) {
            createNewFile();
          }
          return super.setContents(data);
        }

        @Override
        public UnknownFileResource setContents(char[] data) {
          if (!exists()) {
            createNewFile();
          }
          return super.setContents(data);
        }

        @Override
        public UnknownFileResource setContents(String data) {
          if (!exists()) {
            createNewFile();
          }
          return super.setContents(data);
        }
      };
    }

    return (FileResource<?>) child;
  }
  @Override
  public boolean install() {
    if (!this.isInstalled()) {
      for (DirectoryResource folder : this.getSourceFolders()) {
        folder.mkdirs();
      }

      // FIXME WOW this needs to be simplified somehow...
      MavenCoreFacet maven = project.getFacet(MavenCoreFacet.class);
      Model pom = maven.getPOM();
      Build build = pom.getBuild();
      if (build == null) {
        build = new Build();
      }
      List<Plugin> plugins = build.getPlugins();
      Plugin javaSourcePlugin = null;
      for (Plugin plugin : plugins) {
        if ("org.apache.maven.plugins".equals(plugin.getGroupId())
            && "maven-compiler-plugin".equals(plugin.getArtifactId())) {
          javaSourcePlugin = plugin;
        }
      }

      if (javaSourcePlugin == null) {
        javaSourcePlugin = new Plugin();
        // FIXME this should find the most recent version using DependencyResolver
        javaSourcePlugin.setGroupId("org.apache.maven.plugins");
        javaSourcePlugin.setArtifactId("maven-compiler-plugin");
        javaSourcePlugin.setVersion("2.3.2");

        try {
          Xpp3Dom dom =
              Xpp3DomBuilder.build(
                  new ByteArrayInputStream(
                      "<configuration><source>1.6</source><target>1.6</target></configuration>"
                          .getBytes()),
                  "UTF-8");

          javaSourcePlugin.setConfiguration(dom);
        } catch (Exception e) {
          throw new ProjectModelException(e);
        }
      }

      build.addPlugin(javaSourcePlugin);
      pom.setBuild(build);
      maven.setPOM(pom);
    }
    return true;
  }
Esempio n. 8
0
 @Override
 public List<String> getWebPaths(final Resource<?> r) {
   if (r != null) {
     WebResourceFacet web = project.getFacet(WebResourceFacet.class);
     List<DirectoryResource> webRootDirectories = web.getWebRootDirectories();
     for (DirectoryResource d : webRootDirectories) {
       if (r.getFullyQualifiedName().startsWith(d.getFullyQualifiedName())) {
         String path = r.getFullyQualifiedName().substring(d.getFullyQualifiedName().length());
         return getWebPaths(path);
       }
     }
   }
   return new ArrayList<String>();
 }
 @Override
 public DirectoryResource getTestResourceFolder() {
   MavenCoreFacet mavenFacet = project.getFacet(MavenCoreFacet.class);
   Build build = mavenFacet.getPOM().getBuild();
   final String resFolderName;
   if (build != null
       && !build.getTestResources().isEmpty()
       && build.getTestResources().get(0).getDirectory() != null) {
     resFolderName = build.getTestResources().get(0).getDirectory();
   } else {
     resFolderName = "src" + File.separator + "test" + File.separator + "resources";
   }
   DirectoryResource projectRoot = project.getProjectRoot();
   return projectRoot.getChildDirectory(resFolderName);
 }
Esempio n. 10
0
 public static Git clone(final DirectoryResource dir, final String repoUri)
     throws GitAPIException {
   CloneCommand clone =
       Git.cloneRepository().setURI(repoUri).setDirectory(dir.getUnderlyingResourceObject());
   Git git = clone.call();
   return git;
 }
 private UnknownFileResource getImplementationsFile(
     String interfaceName, DirectoryResource servicesDirectory) {
   UnknownFileResource interfaceFile =
       servicesDirectory.getChildOfType(UnknownFileResource.class, interfaceName);
   if (!interfaceFile.exists()) {
     interfaceFile.createNewFile();
   }
   return interfaceFile;
 }
Esempio n. 12
0
  /**
   * Initialize a new git repository.
   *
   * @param dir The directory in which to create a new .git/ folder and repository.
   */
  public static Git init(final DirectoryResource dir) throws IOException {
    FileResource<?> gitDir = dir.getChildDirectory(".git").reify(FileResource.class);
    gitDir.mkdirs();

    RepositoryBuilder db =
        new RepositoryBuilder().setGitDir(gitDir.getUnderlyingResourceObject()).setup();
    Git git = new Git(db.build());
    git.getRepository().create();
    return git;
  }
Esempio n. 13
0
  public List<File> searchForAllResourcesRecursive(String sourcePackage) {
    try {
      System.out.println(">>> search recursive");
      if (sourcePackage.endsWith(".*")) {
        sourcePackage = sourcePackage.substring(0, sourcePackage.length() - 2);
      }
      this.resources = new ArrayList<File>();
      this.searchString = resources.toString();
      DirectoryResource root = Utils.getSourcePackageAsDirResource(project, sourcePackage);
      System.out.println("root: " + root.getUnderlyingResourceObject().getAbsolutePath());
      File[] files = root.getUnderlyingResourceObject().listFiles();
      System.out.println("filesxxx: " + Arrays.asList(files).toString());
      iterateFiles(files);
      return this.resources;

    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
Esempio n. 14
0
  @Override
  public List<String> getWebPaths(Resource<?> r) {
    List<String> results = new ArrayList<String>();

    if (r != null) {
      WebResourceFacet web = project.getFacet(WebResourceFacet.class);
      List<DirectoryResource> webRootDirectories = web.getWebRootDirectories();
      for (DirectoryResource d : webRootDirectories) {
        if (r.getFullyQualifiedName().startsWith(d.getFullyQualifiedName())) {
          String path = r.getFullyQualifiedName().substring(d.getFullyQualifiedName().length());

          for (String p : getWebPaths(path)) {
            if (!results.contains(p)) results.add(p);
          }
          break;
        }
      }
    }
    return results;
  }
  private JavaResource getJavaResource(
      final DirectoryResource sourceDir, final String relativePath) {
    String path =
        relativePath.trim().endsWith(".java")
            ? relativePath.substring(0, relativePath.lastIndexOf(".java"))
            : relativePath;

    path = Packages.toFileSyntax(path) + ".java";
    JavaResource target = sourceDir.getChildOfType(JavaResource.class, path);
    return target;
  }
Esempio n. 16
0
  public List<File> searchForAllResources(String sourcePackage) {
    try {
      this.resources = new ArrayList<File>();
      this.searchString = resources.toString();
      DirectoryResource root = Utils.getSourcePackageAsDirResource(project, sourcePackage);
      File[] files = root.getUnderlyingResourceObject().listFiles();
      System.out.println("files: " + files);

      // search for all resources in the given package
      if (sourcePackage.endsWith(".*")) {
        return Arrays.asList(files);
      }
      // search for resource for given name
      else {
        this.resources.add(Utils.getSourceFileForClass(project, sourcePackage));
        return this.resources;
      }

    } catch (Exception e) {
      e.printStackTrace();
      return null;
    }
  }
Esempio n. 17
0
 public static Git git(final DirectoryResource dir) throws IOException {
   RepositoryBuilder db = new RepositoryBuilder().findGitDir(dir.getUnderlyingResourceObject());
   return new Git(db.build());
 }
 @Override
 public DirectoryResource getSourceFolder() {
   DirectoryResource projectRoot = project.getProjectRoot();
   return projectRoot.getChildDirectory("src" + File.separator + "main" + File.separator + "java");
 }
Esempio n. 19
0
 @Override
 public FileResource<?> getConfigFile() {
   DirectoryResource webRoot = project.getFacet(WebResourceFacet.class).getWebRootDirectory();
   return (FileResource<?>) webRoot.getChild("WEB-INF" + File.separator + "faces-config.xml");
 }