private List<MemoizedFile> filterNonExistantDirs(List<MemoizedFile> dirs) {
   List<MemoizedFile> existingDirs = new ArrayList<>();
   for (MemoizedFile dir : dirs) {
     if (dir.isDirectory()) {
       existingDirs.add(dir);
     }
   }
   return existingDirs;
 }
 private boolean neccessaryChildDirsArePresent(AssetContainer assetContainer) {
   List<MemoizedFile> expectedDirs = getSrcDirs(assetContainer);
   expectedDirs.addAll(getResourceDirs(assetContainer));
   expectedDirs.addAll(getTestDirs(assetContainer));
   expectedDirs.addAll(getThemeDirs(assetContainer));
   for (MemoizedFile dir : expectedDirs) {
     if (dir.isDirectory()) {
       return true;
     }
   }
   return false;
 }
  @Override
  public String toString() {
    StringBuilder errorMessage = new StringBuilder();

    String message = getMessage();
    if (message != null) {
      errorMessage.append(message + "\n");
    }
    if (this.getCause() != null) {
      errorMessage.append("Caused by: " + getCause().getMessage() + "\n");
    }

    if (sourceFile != null) {
      errorMessage.append(
          "Exception thrown whilst attempting to process file:\n '"
              + sourceFile.getAbsolutePath()
              + "'.\n");
    }

    if (lineNumber >= 0) {
      errorMessage.append(" - line " + lineNumber + ", character " + characterNumber + ".\n");
    }

    if (message == null) {
      errorMessage.append("Stack trace:\n");
      StackTraceElement[] stackTrace = getStackTrace();
      for (StackTraceElement traceElement : stackTrace) {
        errorMessage.append("\t" + traceElement.toString() + "\n");
      }
    }

    return errorMessage.toString();
  }
示例#4
0
  private void verifyTopDownItem(PN parentNode) throws Exception {
    Method getItemMethod = parentNodeClass.getMethod(itemMethodName);
    @SuppressWarnings("unchecked")
    CN childNode = (CN) getItemMethod.invoke(parentNode);

    assertEquals(childPath.getAbsolutePath(), childNode.dir().getPath());
  }
示例#5
0
  public void build(App app, MemoizedFile appWarFile) throws ModelOperationException {
    if (!appWarFile.getParentFile().exists())
      throw new ModelOperationException(
          "'" + appWarFile.getParentFile().getPath() + "' does not exist");
    if (appWarFile.exists())
      throw new ModelOperationException(
          "'" + appWarFile.getParentFile().getPath() + "' already exists");

    if (!MissingAppJarChecker.hasCorrectApplicationLibVersions(app)) {
      throw new MissingAppJarsException(app);
    }

    File exportDir = AppBuilderUtilis.getTemporaryExportDir(app);
    AppBuilderUtilis.build(app, exportDir);

    try {
      ZipUtility.zipFolder(exportDir, appWarFile, true);
      appWarFile.incrementFileVersion();
      org.apache.commons.io.FileUtils.deleteQuietly(exportDir);
    } catch (IOException ex) {
      throw new ModelOperationException(ex);
    }
  }
  private List<Asset> discoverFurtherAssetsForChild(
      AssetContainer assetContainer,
      MemoizedFile dir,
      String requirePrefix,
      List<Asset> implicitDependencies,
      AssetRegistry assetDiscoveryInitiator,
      Asset parent) {
    List<Asset> furtherAssetImplicitDependencies = new ArrayList<>();
    furtherAssetImplicitDependencies.addAll(implicitDependencies);
    furtherAssetImplicitDependencies.add(parent);

    List<Asset> discoveredAssets =
        assetDiscoveryInitiator.discoverFurtherAssets(
            dir, requirePrefix, furtherAssetImplicitDependencies);
    List<Asset> dependentAssets = new ArrayList<>();
    if (parent instanceof LinkedAsset) {
      for (Asset dependentAsset : discoveredAssets) {
        if (dependentAsset instanceof SourceModule) {
          continue;
        }
        dependentAssets.add(dependentAsset);
      }
      ((LinkedAsset) parent).addImplicitDependencies(dependentAssets);
    }

    for (MemoizedFile childDir : dir.dirs()) {
      discoveredAssets.addAll(
          createAssetsForChildDir(
              assetContainer,
              childDir,
              requirePrefix,
              implicitDependencies,
              assetDiscoveryInitiator,
              parent));
    }
    return discoveredAssets;
  }
  @Override
  public void discoverAssets(
      AssetContainer assetContainer,
      MemoizedFile dir,
      String requirePrefix,
      List<Asset> implicitDependencies,
      AssetRegistry assetDiscoveryInitiator) {
    // only create assets if we're at the root of the asset container *and* its not a default
    // bladeset
    if (assetContainer instanceof DefaultBladeset
        || !neccessaryChildDirsArePresent(assetContainer)
        || assetContainer.dir() != dir
        || assetDiscoveryInitiator.hasRegisteredAsset(
            BRJSConformantRootDirectoryLinkedAsset.calculateRequirePath(assetContainer))) {
      return;
    }

    List<Asset> assets = new ArrayList<>();

    LinkedAsset rootAsset = new BRJSConformantRootDirectoryLinkedAsset(assetContainer);
    assetDiscoveryInitiator.registerAsset(rootAsset);
    assets.add(rootAsset);

    for (MemoizedFile srcDir : getSrcDirs(assetContainer)) {
      if (useImpliedRequirePrefix(assetContainer)) {
        discoverFurtherAssetsForChild(
            assetContainer,
            srcDir,
            requirePrefix,
            implicitDependencies,
            assetDiscoveryInitiator,
            rootAsset);
      } else {
        discoverFurtherAssetsForChild(
            assetContainer, srcDir, "", implicitDependencies, assetDiscoveryInitiator, rootAsset);
      }
    }

    List<Asset> implicitResourcesDependencies = new ArrayList<>();
    implicitResourcesDependencies.addAll(implicitDependencies);
    implicitResourcesDependencies.add(rootAsset);
    for (MemoizedFile resourceDir : getResourceDirs(assetContainer)) {
      List<Asset> discoveredAssets =
          createAssetsForChildDir(
              assetContainer,
              resourceDir,
              requirePrefix,
              implicitResourcesDependencies,
              assetDiscoveryInitiator,
              rootAsset);
      rootAsset.addImplicitDependencies(discoveredAssets);
    }

    for (MemoizedFile testDir : getTestDirs(assetContainer)) {
      discoverFurtherAssetsForChild(
          assetContainer,
          testDir,
          "test/" + requirePrefix,
          implicitDependencies,
          assetDiscoveryInitiator,
          rootAsset);
    }

    for (MemoizedFile themeDir : getThemeDirs(assetContainer)) {
      String themeRequirePrefix = "theme!" + themeDir.getName() + ":" + requirePrefix;
      List<Asset> discoveredAssets =
          createAssetsForChildDir(
              assetContainer,
              themeDir,
              themeRequirePrefix,
              implicitDependencies,
              assetDiscoveryInitiator,
              rootAsset);
      rootAsset.addImplicitDependencies(discoveredAssets);
    }
  }
  private String calculateImplicitOrExplicitRequirePrefixDirectory(
      AssetContainer assetContainer, String srcDirName) {
    MemoizedFile brjsDir = assetContainer.root().dir();
    String rootPath = srcDirName;

    MemoizedFile srcDir = assetContainer.file(srcDirName);
    if (!srcDir.isDirectory()) {
      return srcDirName;
    }

    String rootRequirePrefix = StringUtils.substringBefore(assetContainer.requirePrefix(), "/");
    MemoizedFile rootRequirePrefixDir = srcDir.file(rootRequirePrefix);

    String nestedRequirePrefixPath = srcDirName + "/" + assetContainer.requirePrefix();
    MemoizedFile nestedRequirePrefixDir = assetContainer.file(nestedRequirePrefixPath);

    MemoizedFile rootPathDir = assetContainer.file(rootPath);
    boolean explicitRequirePrefixDirsExist = nestedRequirePrefixDir.isDirectory();

    if (rootRequirePrefixDir.exists() && !explicitRequirePrefixDirsExist) {
      InvalidRequirePathException wrappedRequirePathException =
          new InvalidRequirePathException(
              String.format(
                  "The location '%s' contains a directory with the same name as the root require prefix ('%s') which suggests it's require prefix is explicitly defined"
                      + " but no folder exists that corresponds to the require prefix for this location ('%s'). Either move all source files and package folders into the directory '%s'"
                      + " to use an explicit directory structure or move all files and package folders into '%s' to allow the require prefix to be calculated automatically.",
                  brjsDir.getRelativePath(assetContainer.file(srcDirName)),
                  rootRequirePrefix,
                  assetContainer.requirePrefix(),
                  brjsDir.getRelativePath(nestedRequirePrefixDir),
                  brjsDir.getRelativePath(rootPathDir)));
      throw new RuntimeException(wrappedRequirePathException);
    }

    BRJS brjs = assetContainer.root();
    Logger logger = brjs.logger(this.getClass());
    if (explicitRequirePrefixDirsExist && useImpliedRequirePrefix(assetContainer)) {
      return nestedRequirePrefixPath;
    }
    logger.debug(
        IMPLICIT_PACKAGE_USED,
        assetContainer.root().dir().getRelativePath(srcDir),
        assetContainer.requirePrefix(),
        assetContainer.requirePrefix());
    return rootPath;
  }