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;
  }
예제 #2
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);
    }
  }