List of usage examples for org.jdom2 Element getNamespace
public Namespace getNamespace()
From source file:org.artifactory.version.converter.v160.SingleRepoTypeConverter.java
License:Open Source License
private void convertVirtualRepos(List<Element> repos) { if (repos == null || repos.isEmpty()) { return;//ww w . ja v a 2 s.c o m } for (Element repo : repos) { List<RepoType> repoTypes = Lists.newArrayList(); fillSharedTypes(repoTypes, repo, true); Element p2 = repo.getChild("p2", repo.getNamespace()); if (p2 != null) { if (StringUtils.equals(p2.getChildText("enabled", p2.getNamespace()), "true")) { addType(repoTypes, p2, RepoType.P2, true); } } String repoKey = repo.getChildText("key", repo.getNamespace()); convertToSingleRepoType(repo, repoKey, repoTypes, true); } }
From source file:org.artifactory.version.converter.v160.SingleRepoTypeConverter.java
License:Open Source License
private void convertToSingleRepoType(Element repo, String repoKey, List<RepoType> repoTypes, boolean virtualRepo) { if (repoTypes.size() >= 1) { repoTypes.stream().skip(1) // First one is used as the final repository type .forEach(repoType -> log.error( "Disabling package '{}' for repo '{}' " + "since only one packaging type is allowed!", repoType, repoKey)); } else {// ww w .ja va 2 s . c om String layoutRef = repo.getChildText("repoLayoutRef", repo.getNamespace()); if (StringUtils.equals(layoutRef, "ivy-default")) { repoTypes.add(RepoType.Ivy); } else if (StringUtils.equals(layoutRef, "gradle-default")) { repoTypes.add(RepoType.Gradle); } else { repoTypes.add(RepoType.Maven); } } // Set the final decided repo type RepoType repoType = repoTypes.get(0); log.info("Setting repository '{}' to type {}", repoKey, repoType); Element typeElement = new Element("type", repo.getNamespace()); typeElement.setText(String.valueOf(repoType).toLowerCase()); repo.addContent(2, new Text("\n ")); repo.addContent(3, typeElement); // add the type after the key property removeEnabledFieldsFromRepo(repo, virtualRepo); }
From source file:org.artifactory.version.converter.v160.SingleRepoTypeConverter.java
License:Open Source License
private void removeEnabledFieldsFromRepo(Element repo, boolean virtualRepo) { for (RepoType repoType : RepoType.values()) { if (repoType.equals(RepoType.P2)) { Element p2 = repo.getChild("p2", repo.getNamespace()); if (p2 != null) { if (p2.getChild("enabled", p2.getNamespace()) != null) { p2.removeChild("enabled", p2.getNamespace()); }// w w w . java 2s . co m } } else if (!repoType.equals(RepoType.YUM)) { //Special handle for YUM config as a repo can still be chosen to be of YUM type but with auto-calc off String field = resolveFieldName(repoType, virtualRepo); if (repo.getChild(field, repo.getNamespace()) != null) { repo.removeChild(field, repo.getNamespace()); } } else { // If the repo type is YUM then we shouldn't remove any field } } }
From source file:org.artifactory.version.converter.v160.SingleRepoTypeConverter.java
License:Open Source License
private void addYumForLegacy(List<RepoType> repoTypes, Element element) { String depth = element.getChildText("yumRootDepth", element.getNamespace()); String groupNames = element.getChildText("yumGroupFileNames", element.getNamespace()); try {// ww w.j a v a2s. c o m if ((StringUtils.isNotBlank(depth) && Integer.valueOf(depth) > 0) || StringUtils.isNotBlank(groupNames)) { repoTypes.add(RepoType.YUM); } } catch (NumberFormatException e) { log.warn("Unresolvable YUM configuration, YUM metadata root depth is {}. ", depth); } }
From source file:org.artifactory.version.converter.v160.SingleRepoTypeConverter.java
License:Open Source License
private void addType(List<RepoType> repoTypes, Element element, RepoType type, boolean virtualRepo) { String fieldName = resolveFieldName(type, virtualRepo); boolean isEnabled = Boolean.valueOf(element.getChildText(fieldName, element.getNamespace())); if (isEnabled) { repoTypes.add(type);//from w w w. j av a 2 s. co m } }
From source file:org.artifactory.version.converter.v162.FolderDownloadConfigConverter.java
License:Open Source License
@Override public void convert(Document doc) { log.info("Starting add default Folder Download config conversion"); Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); Element folderDownloadConfigElement = rootElement.getChild("folderDownloadConfig", namespace); if (folderDownloadConfigElement == null) { log.info("No folder download config found - adding default one"); addDefaultConfig(rootElement, namespace); }/*from w w w . j a v a2 s. c o m*/ log.info("Finished add default Folder Download config conversion"); }
From source file:org.artifactory.version.converter.v162.FolderDownloadConfigConverter.java
License:Open Source License
private void addDefaultConfig(Element rootElement, Namespace namespace) { //Use defaults from descriptor FolderDownloadConfigDescriptor descriptor = new FolderDownloadConfigDescriptor(); Element folderDownload = new Element("folderDownloadConfig", namespace); Namespace folderConfigNs = folderDownload.getNamespace(); ArrayList<Element> elements = Lists.newArrayList(); elements.add(new Element("enabled", folderConfigNs).setText(String.valueOf(descriptor.isEnabled()))); elements.add(new Element("maxDownloadSizeMb", folderConfigNs) .setText(String.valueOf(descriptor.getMaxDownloadSizeMb()))); elements.add(new Element("maxFiles", folderConfigNs).setText(String.valueOf(descriptor.getMaxFiles()))); elements.add(new Element("maxConcurrentRequests", folderConfigNs) .setText(String.valueOf(descriptor.getMaxConcurrentRequests()))); folderDownload.addContent(elements); rootElement.addContent(rootElement.getContentSize(), folderDownload); }
From source file:org.artifactory.version.converter.v166.SourceDeletedDetectionConverter.java
License:Open Source License
@Override public void convert(Document doc) { log.info("Converting repositories for SourceDeletedDetection support"); Element rootElement = doc.getRootElement(); Namespace namespace = rootElement.getNamespace(); Element localRepos = rootElement.getChild("localRepositories", namespace); if (localRepos != null) { convertLocalRepos(localRepos.getChildren()); }/*from w ww.j a v a2 s. c om*/ Element remoteRepos = rootElement.getChild("remoteRepositories", namespace); if (remoteRepos != null) { convertRemoteRepos(remoteRepos.getChildren()); } Element virtualRepos = rootElement.getChild("virtualRepositories", namespace); if (virtualRepos != null) { convertVirtualRepos(virtualRepos.getChildren()); } log.info("Finished Converting repositories for SourceDeletedDetection support"); }
From source file:org.artifactory.version.converter.v166.SourceDeletedDetectionConverter.java
License:Open Source License
private void convertRepositories(List<Element> repos) { for (Element repo : repos) { Element contentSynchronisation = repo.getChild("contentSynchronisation", repo.getNamespace()); if (contentSynchronisation != null && contentSynchronisation.getChild("source", contentSynchronisation.getNamespace()) == null) { addOriginAbsenceDetectionElement(contentSynchronisation); }//from w ww . ja v a 2 s . com } }
From source file:org.artifactory.version.converter.v166.SourceDeletedDetectionConverter.java
License:Open Source License
private void addOriginAbsenceDetectionElement(Element contentSynchronisation) { Element source = new Element("source", contentSynchronisation.getNamespace()); Element originAbsenceDetection = new Element("originAbsenceDetection", source.getNamespace()); originAbsenceDetection.addContent("false"); source.addContent(source.getContentSize(), originAbsenceDetection); contentSynchronisation.addContent(contentSynchronisation.getContentSize(), source); }