/* (non-Javadoc)
@see com.tobedevoured.naether.api.Naether#addBuildArtifact(java.lang.String, java.lang.String)
197473
public void addBuildArtifact(String notation, String path) throws NaetherException {
        Artifact artifact = new DefaultArtifact(notation);
        artifact = artifact.setFile( new File(path) );
        
        this.buildArtifacts.add( artifact );
        
        File tempPom = null;
        try {
            tempPom = File.createTempFile( Const.POM, "xml" );
        } catch (IOException e) {
            throw new NaetherException( "Failed to create temp file", e );
        }
        
        tempPom.deleteOnExit();
        
        Project project = new Project();
        project.setGroupId( artifact.getGroupId() );
        project.setArtifactId( artifact.getArtifactId() );
        project.setVersion( artifact.getBaseVersion() );
        try {
            project.writePom( tempPom );
        } catch (ProjectException e) {
            throw new NaetherException( "Failed to create temp POM", e );
        }
        
        String pomNotation = new StringBuilder( artifact.getGroupId() ).append(":")
            .append( artifact.getArtifactId() ).append(":")
            .append( Const.POM).append(":").append( artifact.getBaseVersion() ).toString();
        
        artifact = new DefaultArtifact(pomNotation);
        artifact = artifact.setFile( tempPom );
        
        this.buildArtifacts.add( artifact );
    }
1060371
public ISarlConstructorBuilder addSarlConstructor() {
		ISarlConstructorBuilder builder = this.iSarlConstructorBuilderProvider.get();
		builder.eInit(getSarlEvent(), getTypeResolutionContext());
		return builder;
	}
206211
@Override
    public T addAsWebInfResource(final Asset resource, final String target) throws IllegalArgumentException {
        Validate.notNull(resource, "Resource should be specified");
        Validate.notNullOrEmpty(target, "Target should be specified");

        return addAsWebInfResource(resource, ArchivePaths.create(target));
    }
381270
protected void buildAdditionalPublicanCfg(final BuildData buildData) throws BuildProcessingException {
        final ContentSpec contentSpec = buildData.getContentSpec();
        final Map<String, String> overrides = buildData.getBuildOptions().getOverrides();
        final Map<String, String> additionalPublicanCfgs = contentSpec.getAllAdditionalPublicanCfgs();

        for (final Map.Entry<String, String> entry : additionalPublicanCfgs.entrySet()) {
            final String brandOverride = overrides.containsKey(CSConstants.BRAND_OVERRIDE) ? overrides.get(
                    CSConstants.BRAND_OVERRIDE) : (overrides.containsKey(CSConstants.BRAND_ALT_OVERRIDE) ? overrides.get(
                    CSConstants.BRAND_ALT_OVERRIDE) : null);
            final String brand = brandOverride != null ? brandOverride : (contentSpec.getBrand() == null ? getDefaultBrand(
                    buildData) : contentSpec.getBrand());

            // Setup publican.cfg
            final StringBuilder publicanCfg = new StringBuilder("xml_lang: ").append(buildData.getOutputLocale()).append("\n");
            publicanCfg.append("type: ").append(contentSpec.getBookType().toString().replaceAll("-Draft", "") + "\n");
            publicanCfg.append("brand: ").append(brand).append("\n");

            // Add the custom content
            publicanCfg.append(DocBookBuildUtilities.cleanUserPublicanCfg(entry.getValue()));

            // Add the dtdver property
            if (buildData.getDocBookVersion() == DocBookVersion.DOCBOOK_50) {
                publicanCfg.append("dtdver: \"5.0\"\n");
            }

            // Add docname if it wasn't specified and the escaped title is valid
            Matcher m = null;
            if (BuilderConstants.VALID_PUBLICAN_DOCNAME_PATTERN.matcher(buildData.getEscapedBookTitle()).matches()) {
                m = DOCNAME_PATTERN.matcher(publicanCfg);
                if (!m.find()) {
                    publicanCfg.append("docname: ").append(buildData.getEscapedBookTitle().replaceAll("_", " ")).append("\n");
                }
            }

            // Add product if it wasn't specified
            m = PRODUCT_PATTERN.matcher(publicanCfg);
            if (!m.find()) {
                publicanCfg.append("product: ").append(escapeProduct(buildData.getOriginalBookProduct())).append("\n");
            }

            // Add the mainfile attribute
            publicanCfg.append("mainfile: ").append(buildData.getRootBookFileName()).append("\n");

            // Add version if it wasn't specified
            m = VERSION_PATTERN.matcher(publicanCfg);
            if (!m.find()) {
                String version = contentSpec.getBookVersion();
                if (isNullOrEmpty(version)) {
                    version = DocBookBuildUtilities.getKeyValueNodeText(buildData, contentSpec.getVersionNode());
                }
                if (isNullOrEmpty(version)) {
                    version = BuilderConstants.DEFAULT_VERSION;
                }
                publicanCfg.append("version: ").append(escapeVersion(version)).append("\n");
            }

            String fixedPublicanCfg = publicanCfg.toString();

            if (buildData.getBuildOptions().getPublicanShowRemarks()) {
                // Remove any current show_remarks definitions
                if (publicanCfg.indexOf("show_remarks") != -1) {
                    fixedPublicanCfg = fixedPublicanCfg.replaceAll("show_remarks\\s*:\\s*\\d+\\s*(\\r)?(\\n)?", "");
                }
                fixedPublicanCfg += "show_remarks: 1\n";
            }

            addToZip(buildData.getRootBookFolder() + entry.getKey(), fixedPublicanCfg, buildData);
        }
    }
883254
@Override
  public void setRefid(final Reference r) throws BuildException {
    if (!this.defineList.isEmpty()) {
      throw tooManyAttributes();
    }
    super.setRefid(r);
  }
667489
protected void addProperties(Element element, BeanDefinitionBuilder builder) {
        NamedNodeMap attributes = element.getAttributes();
        
        for (int i = 0; i < attributes.getLength(); i++) {
            Node node = attributes.item(i);
            String attrName = getNodeName(node);
            attrName = "class".equals(attrName) ? "clazz" : attrName;
            builder.addPropertyValue(attrName, node.getNodeValue());
        }
    }
352363
protected void updateBuild(Build value, String xmlTag, Counter counter, Element element)
   {
      boolean shouldExist = value != null;
      Element root = updateElement(counter, element, xmlTag, shouldExist);
      if (shouldExist)
      {
         Counter innerCount = new Counter(counter.getDepth() + 1);
         findAndReplaceSimpleElement(innerCount, root, "sourceDirectory", value.getSourceDirectory(), null);
         findAndReplaceSimpleElement(innerCount, root, "scriptSourceDirectory", value.getScriptSourceDirectory(),
                  null);
         findAndReplaceSimpleElement(innerCount, root, "testSourceDirectory", value.getTestSourceDirectory(), null);
         findAndReplaceSimpleElement(innerCount, root, "outputDirectory", value.getOutputDirectory(), null);
         findAndReplaceSimpleElement(innerCount, root, "testOutputDirectory", value.getTestOutputDirectory(), null);
         iterateExtension(innerCount, root, value.getExtensions(), "extensions", "extension");
         findAndReplaceSimpleElement(innerCount, root, "defaultGoal", value.getDefaultGoal(), null);
         iterateResource(innerCount, root, value.getResources(), "resources", "resource");
         iterateResource(innerCount, root, value.getTestResources(), "testResources", "testResource");
         findAndReplaceSimpleElement(innerCount, root, "directory", value.getDirectory(), null);
         findAndReplaceSimpleElement(innerCount, root, "finalName", value.getFinalName(), null);
         findAndReplaceSimpleLists(innerCount, root, value.getFilters(), "filters", "filter");
         updatePluginManagement(value.getPluginManagement(), "pluginManagement", innerCount, root);
         iteratePlugin(innerCount, root, value.getPlugins(), "plugins", "plugin");
      } // end if
   }
897642
static void addTagToBuilder(Tag tag, TagMapBuilderImpl builder) {
    builder.put(tag.getKey(), tag.getValue(), tag.getTagMetadata());
  }
336946
public void addFieldInfo (@Nonnull @Nonempty final String sFieldName, @Nonnull @Nonempty final String sText)
  {
    add (SingleError.builderInfo ().setErrorFieldName (sFieldName).setErrorText (sText).build ());
  }
813320
public void addConstantFactor(String factorName, PlateFactor factor) {
    constantFactors.add(factor);
    constantFactorNames.add(factorName);
  }
1085375
protected void addAttributeName() {
        if (Strings.isNotEmpty(builder)) {
            attribute = builder.toString();
            Strings.clearBuilder(builder);
        }
    }
1275571
@SuppressWarnings("unchecked")
    public static boolean addPropertyDefault(PropertiesImpl props, PropertyDefinition<?> propDef) {

        if ((props == null) || (props.getProperties() == null)) {
            throw new IllegalArgumentException("Props must not be null!");
        }

        if (propDef == null) {
            return false;
        }

        List<?> defaultValue = propDef.getDefaultValue();
        if ((defaultValue != null) && (!defaultValue.isEmpty())) {
            switch (propDef.getPropertyType()) {
                case BOOLEAN:
                    props.addProperty(new PropertyBooleanImpl(propDef.getId(), (List<Boolean>)defaultValue));
                    break;
                case DATETIME:
                    props.addProperty(new PropertyDateTimeImpl(propDef.getId(), (List<GregorianCalendar>)defaultValue));
                    break;
                case DECIMAL:
                    props.addProperty(new PropertyDecimalImpl(propDef.getId(), (List<BigDecimal>)defaultValue));
                    break;
                case HTML:
                    props.addProperty(new PropertyHtmlImpl(propDef.getId(), (List<String>)defaultValue));
                    break;
                case ID:
                    props.addProperty(new PropertyIdImpl(propDef.getId(), (List<String>)defaultValue));
                    break;
                case INTEGER:
                    props.addProperty(new PropertyIntegerImpl(propDef.getId(), (List<BigInteger>)defaultValue));
                    break;
                case STRING:
                    props.addProperty(new PropertyStringImpl(propDef.getId(), (List<String>)defaultValue));
                    break;
                case URI:
                    props.addProperty(new PropertyUriImpl(propDef.getId(), (List<String>)defaultValue));
                    break;
                default:
                    throw new RuntimeException("Unknown datatype! Spec change?");
            }

            return true;
        }

        return false;
    }
483291
@Override
	public Future<ModuleBuildReader> getBuild(HttpServletRequest request) {
		String errorMessage = MessageFormat.format(
				Messages.NotFoundModule_0,
				new Object[]{StringUtil.escapeForJavaScript(uri.toString())}
		);
		return
			new CompletedFuture<ModuleBuildReader>(
				new ModuleBuildReader(
					new ErrorModuleReader(
						ErrorModuleReader.ConsoleMethod.error,
						errorMessage,
						getModuleName(),
						request
					), true,
					null,
					errorMessage
				)
			);
	}
633970
@JavaScriptMethod
    @SuppressWarnings({"UnusedDeclaration"})
    public LoadBuildsResponse loadBuild(String buildId) {
        LoadBuildsResponse response = new LoadBuildsResponse();
        // When we load a new build we need also to reset the promotion plugin.
        // The null plugin is related to 'None' plugin.
        setPromotionPlugin(null);
        try {
            this.currentPromotionCandidate = promotionCandidates.get(buildId);
            if (this.currentPromotionCandidate == null) {
                throw new IllegalArgumentException("Can't find build by ID: " + buildId);
            }
            List<String> repositoryKeys = getRepositoryKeys();
            List<UserPluginInfo> plugins = getPromotionsUserPluginInfo();
            PromotionConfig promotionConfig = getPromotionConfig();
            String defaultTargetRepository = getDefaultPromotionTargetRepository();
            if (StringUtils.isNotBlank(defaultTargetRepository) && repositoryKeys.contains(defaultTargetRepository)) {
                promotionConfig.setTargetRepo(defaultTargetRepository);
            }
            response.addRepositories(repositoryKeys);
            response.setPlugins(plugins);
            response.setPromotionConfig(promotionConfig);
            response.setSuccess(true);
        } catch (Exception e) {
            response.setResponseMessage(e.getMessage());
        }
        return response;
    }
1338194
private String applyPublicanCfgOverrides(final BuildData buildData, final String publicanCfg) {
        final Map<String, String> publicanCfgOverrides = buildData.getBuildOptions().getPublicanCfgOverrides();
        String retValue = publicanCfg;

        // Loop over each override and remove any entries that may exist and then append the new entry
        for (final Map.Entry<String, String> publicanCfgOverrideEntry : publicanCfgOverrides.entrySet()) {
            retValue = retValue.replaceFirst(publicanCfgOverrideEntry.getKey() + "\\s*:.*?(\\r)?\\n", "");
            retValue += publicanCfgOverrideEntry.getKey() + ": " + publicanCfgOverrideEntry.getValue() + "\n";
        }

        return retValue;
    }
1050482
@Override
	public String renderBuild(HttpServletRequest request, Set<String> dependentFeatures) {
		String result;
		if (build instanceof IModuleBuildRenderer) {
			result = ((IModuleBuildRenderer)build).renderBuild(request, dependentFeatures);
		} else {
			result = build.toString();
		}
		return result;
	}
76428
public void setSecondaryArtifacts(java.util.Collection<ProjectArtifacts> secondaryArtifacts) {
        if (secondaryArtifacts == null) {
            this.secondaryArtifacts = null;
            return;
        }

        this.secondaryArtifacts = new java.util.ArrayList<ProjectArtifacts>(secondaryArtifacts);
    }