From dbd556f2420b8888faa21fcfafce606043a6541c Mon Sep 17 00:00:00 2001 From: Eclipse Equinox Bot Date: Sun, 9 Mar 2025 03:21:32 +0000 Subject: [PATCH] Perform clean code of bundles/org.eclipse.equinox.p2.updatesite --- .../p2/updatesite/CategoryParser.java | 115 ++++++++----- .../CategoryPublisherApplication.java | 6 +- .../p2/updatesite/CategoryXMLAction.java | 3 +- .../p2/updatesite/DefaultSiteParser.java | 91 +++++++---- .../internal/p2/updatesite/DigestParser.java | 18 ++- .../p2/updatesite/LocalUpdateSiteAction.java | 13 +- .../p2/updatesite/RemoteUpdateSiteAction.java | 12 +- .../internal/p2/updatesite/SiteBundle.java | 65 +++++--- .../internal/p2/updatesite/SiteCategory.java | 6 +- .../internal/p2/updatesite/SiteFeature.java | 68 +++++--- .../internal/p2/updatesite/SiteIU.java | 15 +- .../internal/p2/updatesite/SiteModel.java | 54 ++++--- .../internal/p2/updatesite/SiteXMLAction.java | 136 ++++++++++------ .../internal/p2/updatesite/UpdateSite.java | 153 ++++++++++++------ .../UpdateSitePublisherApplication.java | 6 +- .../p2/updatesite/VersionSuffixGenerator.java | 44 +++-- .../UpdateSiteArtifactRepositoryFactory.java | 15 +- .../UpdateSiteMetadataRepositoryFactory.java | 18 ++- 18 files changed, 551 insertions(+), 287 deletions(-) diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java index d35fbcee17..28cd2d1737 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryParser.java @@ -120,14 +120,16 @@ public CategoryParser(URI siteLocation) { log(e); } - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("Created"); //$NON-NLS-1$ + } } public int currentState() { Integer state = stateStack.peek(); - if (state != null) + if (state != null) { return state.intValue(); + } return STATE_IGNORED_ELEMENT; } @@ -151,10 +153,12 @@ public void characters(char[] ch, int start, int length) { case STATE_PARAM : text = text.trim(); String existing = null; - if (objectStack.peek() instanceof String) + if (objectStack.peek() instanceof String) { existing = (String) objectStack.pop(); - if (existing != null) + } + if (existing != null) { text = existing + text; + } objectStack.push(text); break; default : @@ -211,8 +215,9 @@ public void endElement(String uri, String localName, String qName) { SiteIU completeIU = (SiteIU) objectStack.pop(); String id = completeIU.getID(); String expression = completeIU.getQueryExpression(); - if (id == null && expression == null) + if (id == null && expression == null) { internalError("The IU must specify an id or an expression to match against."); //$NON-NLS-1$ + } break; case STATE_EXPRESSION : @@ -221,8 +226,9 @@ public void endElement(String uri, String localName, String qName) { text = (String) objectStack.pop(); SiteIU iu = (SiteIU) objectStack.peek(); iu.setQueryExpression(text); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("Found Expression: " + text); //$NON-NLS-1$ + } } break; case STATE_PARAM : @@ -231,8 +237,9 @@ public void endElement(String uri, String localName, String qName) { text = (String) objectStack.pop(); SiteIU iu = (SiteIU) objectStack.peek(); iu.addQueryParams(text); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("Found Param: " + text); //$NON-NLS-1$ + } } break; @@ -273,15 +280,17 @@ public void endElement(String uri, String localName, String qName) { text = text.trim(); info = (URLEntry) objectStack.pop(); - if (text != null) + if (text != null) { info.setAnnotation(text); + } SiteModel siteModel = (SiteModel) objectStack.peek(); // override description. // do not raise error as previous description may be default one // when parsing site tag - if (DESCRIPTION_SITE_ALREADY_SEEN) + if (DESCRIPTION_SITE_ALREADY_SEEN) { debug(NLS.bind(Messages.DefaultSiteParser_ElementAlreadySet, (new String[] {getState(state)}))); + } siteModel.setDescription(info); DESCRIPTION_SITE_ALREADY_SEEN = true; break; @@ -303,13 +312,14 @@ public void endElement(String uri, String localName, String qName) { text = text.trim(); info = (URLEntry) objectStack.pop(); - if (text != null) + if (text != null) { info.setAnnotation(text); + } SiteCategory category = (SiteCategory) objectStack.peek(); - if (category.getDescription() != null) + if (category.getDescription() != null) { internalError(NLS.bind(Messages.DefaultSiteParser_ElementAlreadySet, (new String[] {getState(state), category.getLabel()}))); - else { + } else { checkTranslated(info.getAnnotation()); category.setDescription(info.getAnnotation()); } @@ -320,8 +330,9 @@ public void endElement(String uri, String localName, String qName) { break; } - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End Element:" + uri + ":" + localName + ":" + qName);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } } /* @@ -337,8 +348,9 @@ private void error(IStatus error) { } status.add(error); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { LogHelper.log(error); + } } /** @@ -447,16 +459,18 @@ private void handleFeatureState(String elementName, Attributes attributes) { if (elementName.equals(CATEGORY)) { stateStack.push(Integer.valueOf(STATE_CATEGORY)); processCategory(attributes); - } else + } else { internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, (new String[] {elementName, getState(currentState())}))); + } } private void handleBundleState(String elementName, Attributes attributes) { if (elementName.equals(CATEGORY)) { stateStack.push(Integer.valueOf(STATE_CATEGORY)); processCategory(attributes); - } else + } else { internalErrorUnknownTag(NLS.bind(Messages.DefaultSiteParser_UnknownElement, (new String[] {elementName, getState(currentState())}))); + } } private void handleInitialState(String elementName, Attributes attributes) throws SAXException { @@ -591,15 +605,16 @@ private boolean leadingSpace(String str) { */ private void logStatus(SAXParseException ex) { String name = ex.getSystemId(); - if (name == null) + if (name == null) { name = ""; //$NON-NLS-1$ - else + } else { name = name.substring(1 + name.lastIndexOf("/")); //$NON-NLS-1$ + } String msg; - if (name.equals("")) //$NON-NLS-1$ + if (name.equals("")) { //$NON-NLS-1$ msg = NLS.bind(Messages.DefaultSiteParser_ErrorParsing, (new String[] {ex.getMessage()})); - else { + } else { String[] values = new String[] {name, Integer.toString(ex.getLineNumber()), Integer.toString(ex.getColumnNumber()), ex.getMessage()}; msg = NLS.bind(Messages.DefaultSiteParser_ErrorlineColumnMessage, values); } @@ -619,8 +634,9 @@ private void logStatus(SAXParseException ex) { public SiteModel parse(InputStream in) throws SAXException, IOException { stateStack.push(Integer.valueOf(STATE_INITIAL)); parser.parse(new InputSource(in), this); - if (objectStack.isEmpty()) + if (objectStack.isEmpty()) { throw new SAXException(Messages.DefaultSiteParser_NoSiteTag); + } if (objectStack.peek() instanceof SiteModel) { SiteModel site = (SiteModel) objectStack.pop(); site.setMessageKeys(messageKeys); @@ -639,8 +655,9 @@ public SiteModel parse(InputStream in) throws SAXException, IOException { */ private void processArchive(Attributes attributes) { // don't care about archives in category xml - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing Archive"); //$NON-NLS-1$ + } } /* @@ -660,8 +677,9 @@ private void processCategory(Attributes attributes) { ((SiteCategory) obj).addCategoryName(category); } - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing Category: name:" + category); //$NON-NLS-1$ + } } /* @@ -679,8 +697,9 @@ private void processCategoryDef(Attributes attributes) { site.addCategory(category); objectStack.push(category); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing CategoryDef: name:" + name + " label:" + label); //$NON-NLS-1$ //$NON-NLS-2$ + } } /* @@ -722,8 +741,9 @@ private void processStatsInfo(Attributes attributes) { // Ignore if not valid. } - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing Repository Reference: location:" + location); //$NON-NLS-1$ + } } /* @@ -739,8 +759,9 @@ private void processStatsFeature(Attributes attributes) { boolean noId = (id == null || id.trim().equals("")); //$NON-NLS-1$ // We need to have id and version, or the url, or both. - if (noId) + if (noId) { internalError(NLS.bind(Messages.DefaultSiteParser_Missing, (new String[] {"url", getState(currentState())}))); //$NON-NLS-1$ + } feature.setFeatureIdentifier(id); feature.setFeatureVersion(ver); @@ -750,8 +771,9 @@ private void processStatsFeature(Attributes attributes) { objectStack.push(feature); feature.setSiteModel(site); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End Processing Stats Feature Tag: id:" + id + " version:" + ver); //$NON-NLS-1$ //$NON-NLS-2$ } + } } /* @@ -767,8 +789,9 @@ private void processStatsBundle(Attributes attributes) { boolean noId = (id == null || id.trim().equals("")); //$NON-NLS-1$ // We need to have id and version, or the url, or both. - if (noId) + if (noId) { internalError(NLS.bind(Messages.DefaultSiteParser_Missing, (new String[] {"url", getState(currentState())}))); //$NON-NLS-1$ + } bundle.setBundleIdentifier(id); bundle.setBundleVersion(ver); @@ -778,8 +801,9 @@ private void processStatsBundle(Attributes attributes) { objectStack.push(bundle); bundle.setSiteModel(site); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End Processing Stats Bundle Tag: id:" + id + " version:" + ver); //$NON-NLS-1$ //$NON-NLS-2$ + } } /* @@ -798,8 +822,9 @@ private void processFeature(Attributes attributes) { boolean noId = (id == null || id.trim().equals("")); //$NON-NLS-1$ // We need to have id and version, or the url, or both. - if (noId) + if (noId) { internalError(NLS.bind(Messages.DefaultSiteParser_Missing, (new String[] {"url", getState(currentState())}))); //$NON-NLS-1$ + } feature.setFeatureIdentifier(id); feature.setFeatureVersion(ver); @@ -813,8 +838,9 @@ private void processFeature(Attributes attributes) { objectStack.push(feature); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End Processing Feature Tag: id:" + id + " version:" + ver); //$NON-NLS-1$ //$NON-NLS-2$ + } } /* @@ -833,8 +859,9 @@ private void processBundle(Attributes attributes) { boolean noId = (id == null || id.trim().equals("")); //$NON-NLS-1$ // We need to have id and version, or the url, or both. - if (noId) + if (noId) { internalError(NLS.bind(Messages.DefaultSiteParser_Missing, (new String[] {"url", getState(currentState())}))); //$NON-NLS-1$ + } bundle.setBundleIdentifier(id); bundle.setBundleVersion(ver); @@ -848,8 +875,9 @@ private void processBundle(Attributes attributes) { objectStack.push(bundle); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End Processing Bundle Tag: id:" + id + " version:" + ver); //$NON-NLS-1$ //$NON-NLS-2$ + } } /* @@ -871,8 +899,9 @@ private void processIU(Attributes attributes) { site.addIU(iu); objectStack.push(iu); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing iu."); //$NON-NLS-1$ + } } /* @@ -882,8 +911,9 @@ private void processExpression(Attributes attributes) { SiteIU iu = (SiteIU) objectStack.peek(); iu.setQueryType(attributes.getValue("type")); //$NON-NLS-1$ - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing Expression: " + iu.getQueryType()); //$NON-NLS-1$ + } } /* @@ -891,16 +921,18 @@ private void processExpression(Attributes attributes) { */ private void processQuery(Attributes attributes) { // TODO may have simple attriutes for id and range - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing Query."); //$NON-NLS-1$ + } } /* * process param info */ private void processParam(Attributes attributes) { - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing Param."); //$NON-NLS-1$ + } } /* @@ -911,8 +943,9 @@ private void processInfo(Attributes attributes) { String infoURL = attributes.getValue("url"); //$NON-NLS-1$ inf.setURL(infoURL); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("Processed Info: url:" + infoURL); //$NON-NLS-1$ + } objectStack.push(inf); } @@ -925,8 +958,9 @@ private void processSite(Attributes attributes) { SiteModel site = new SiteModel(); objectStack.push(site); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End process Site tag."); //$NON-NLS-1$ + } } @@ -1020,7 +1054,8 @@ private boolean trailingSpace(String str) { // Add translatable strings from the site.xml // to the list of message keys. private void checkTranslated(String value) { - if (value != null && value.length() > 1 && value.startsWith("%")) //$NON-NLS-1$ + if (value != null && value.length() > 1 && value.startsWith("%")) { //$NON-NLS-1$ messageKeys.add(value.substring(1)); + } } } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryPublisherApplication.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryPublisherApplication.java index 7678e96a35..d5c1287548 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryPublisherApplication.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryPublisherApplication.java @@ -78,11 +78,13 @@ protected void processParameter(String arg, String parameter, PublisherInfo pinf this.append = true; // Always append, otherwise we will end up with nothing - if (arg.equalsIgnoreCase("-categoryQualifier")) //$NON-NLS-1$ + if (arg.equalsIgnoreCase("-categoryQualifier")) { //$NON-NLS-1$ categoryQualifier = parameter; + } - if (arg.equalsIgnoreCase("-categoryDefinition")) //$NON-NLS-1$ + if (arg.equalsIgnoreCase("-categoryDefinition")) { //$NON-NLS-1$ categoryDefinition = URIUtil.fromString(parameter); + } } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryXMLAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryXMLAction.java index c10377362d..4500979db0 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryXMLAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/CategoryXMLAction.java @@ -38,8 +38,9 @@ public IStatus perform(IPublisherInfo publisherInfo, IPublisherResult results, I } catch (ProvisionException e) { return new Status(IStatus.ERROR, Activator.ID, Messages.Error_generating_category, e); } - if (updateSite == null) + if (updateSite == null) { return new Status(IStatus.ERROR, Activator.ID, Messages.Error_generating_category); + } return super.perform(publisherInfo, results, monitor); } } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DefaultSiteParser.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DefaultSiteParser.java index 97757d9650..960b840bf6 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DefaultSiteParser.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DefaultSiteParser.java @@ -108,8 +108,9 @@ private static URLEntry[] getAssociateSites(String associateSitesURL) { DocumentBuilderFactory domFactory = SecureXMLUtil.newSecureDocumentBuilderFactory(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document document = builder.parse(associateSitesURL); - if (document == null) + if (document == null) { return null; + } NodeList mirrorNodes = document.getElementsByTagName(ASSOCIATE_SITE); URLEntry[] mirrors = new URLEntry[mirrorNodes.getLength()]; for (int i = 0; i < mirrorNodes.getLength(); i++) { @@ -120,8 +121,9 @@ private static URLEntry[] getAssociateSites(String associateSitesURL) { mirrors[i].setURL(infoURL); mirrors[i].setAnnotation(label); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("Processed mirror: url:" + infoURL + " label:" + label); //$NON-NLS-1$ //$NON-NLS-2$ + } } return mirrors; } catch (Exception e) { @@ -130,8 +132,9 @@ private static URLEntry[] getAssociateSites(String associateSitesURL) { || associateSitesURL.startsWith("https://") //$NON-NLS-1$ || associateSitesURL.startsWith("file://") //$NON-NLS-1$ || associateSitesURL.startsWith("ftp://") //$NON-NLS-1$ - || associateSitesURL.startsWith("jar://"))) //$NON-NLS-1$ + || associateSitesURL.startsWith("jar://"))) { //$NON-NLS-1$ log(Messages.DefaultSiteParser_mirrors, e); + } return null; } } @@ -168,8 +171,9 @@ public DefaultSiteParser(URI siteLocation) { log(e); } - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("Created"); //$NON-NLS-1$ + } } /** @@ -183,8 +187,9 @@ public void characters(char[] ch, int start, int length) { String text = new String(ch, start, length); // only push if description int state = stateStack.peek().intValue(); - if (state == STATE_DESCRIPTION_SITE || state == STATE_DESCRIPTION_CATEGORY_DEF) + if (state == STATE_DESCRIPTION_SITE || state == STATE_DESCRIPTION_CATEGORY_DEF) { objectStack.push(text); + } } @@ -259,15 +264,17 @@ public void endElement(String uri, String localName, String qName) { text = text.trim(); info = (URLEntry) objectStack.pop(); - if (text != null) + if (text != null) { info.setAnnotation(text); + } SiteModel siteModel = (SiteModel) objectStack.peek(); // override description. // do not raise error as previous description may be default one // when parsing site tag - if (DESCRIPTION_SITE_ALREADY_SEEN) + if (DESCRIPTION_SITE_ALREADY_SEEN) { debug(NLS.bind(Messages.DefaultSiteParser_ElementAlreadySet, (new String[] { getState(state) }))); + } siteModel.setDescription(info); DESCRIPTION_SITE_ALREADY_SEEN = true; break; @@ -289,14 +296,15 @@ public void endElement(String uri, String localName, String qName) { text = text.trim(); info = (URLEntry) objectStack.pop(); - if (text != null) + if (text != null) { info.setAnnotation(text); + } SiteCategory category = (SiteCategory) objectStack.peek(); - if (category.getDescription() != null) + if (category.getDescription() != null) { internalError(NLS.bind(Messages.DefaultSiteParser_ElementAlreadySet, (new String[] { getState(state), category.getLabel() }))); - else { + } else { checkTranslated(info.getAnnotation()); category.setDescription(info.getAnnotation()); } @@ -307,8 +315,9 @@ public void endElement(String uri, String localName, String qName) { break; } - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End Element:" + uri + ":" + localName + ":" + qName);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } } /* @@ -324,8 +333,9 @@ private void error(IStatus error) { } status.add(error); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { LogHelper.log(error); + } } /** @@ -585,14 +595,16 @@ private boolean leadingSpace(String str) { */ private void logStatus(SAXParseException ex) { String name = ex.getSystemId(); - if (name == null) + if (name == null) { name = ""; //$NON-NLS-1$ - else + } else { name = name.substring(1 + name.lastIndexOf("/")); //$NON-NLS-1$ + } String msg; - if (name.equals("")) //$NON-NLS-1$ + if (name.equals("")) { //$NON-NLS-1$ name = siteLocation.toString(); + } String[] values = new String[] { name, Integer.toString(ex.getLineNumber()), Integer.toString(ex.getColumnNumber()), ex.getMessage() }; msg = NLS.bind(Messages.DefaultSiteParser_ErrorlineColumnMessage, values); @@ -613,8 +625,9 @@ public SiteModel parse(InputStream in) throws SAXException, IOException { stateStack.push(Integer.valueOf(STATE_INITIAL)); currentState = stateStack.peek().intValue(); parser.parse(new InputSource(in), this); - if (objectStack.isEmpty()) + if (objectStack.isEmpty()) { throw new SAXException(Messages.DefaultSiteParser_NoSiteTag); + } if (objectStack.peek() instanceof SiteModel) { SiteModel site = (SiteModel) objectStack.pop(); site.setMessageKeys(messageKeys); @@ -651,8 +664,9 @@ private void processArchive(Attributes attributes) { SiteModel site = (SiteModel) objectStack.peek(); site.addArchive(archive); } - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing Archive: path:" + id + " url:" + url);//$NON-NLS-1$ //$NON-NLS-2$ + } } @@ -670,8 +684,9 @@ private void processCategory(Attributes attributes) { bundle.addCategoryName(category); } - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing Category: name:" + category); //$NON-NLS-1$ + } } /* @@ -689,8 +704,9 @@ private void processCategoryDef(Attributes attributes) { site.addCategory(category); objectStack.push(category); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End processing CategoryDef: name:" + name + " label:" + label); //$NON-NLS-1$ //$NON-NLS-2$ + } } /* @@ -711,12 +727,13 @@ private void processFeature(Attributes attributes) { // We need to have id and version, or the url, or both. if (noURL) { - if (noId || noVersion) + if (noId || noVersion) { internalError( NLS.bind(Messages.DefaultSiteParser_Missing, (new String[] { "url", getState(currentState) }))); //$NON-NLS-1$ - else + } else { // default url urlInfo = FEATURES + id + '_' + ver; // + } } feature.setURLString(urlInfo); @@ -736,8 +753,9 @@ private void processFeature(Attributes attributes) { // get label if it exists String label = attributes.getValue("label"); //$NON-NLS-1$ if (label != null) { - if ("".equals(label.trim())) //$NON-NLS-1$ + if ("".equals(label.trim())) { //$NON-NLS-1$ label = null; + } checkTranslated(label); } feature.setLabel(label); @@ -768,8 +786,9 @@ private void processFeature(Attributes attributes) { objectStack.push(feature); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End Processing DefaultFeature Tag: url:" + urlInfo + " type:" + type); //$NON-NLS-1$ //$NON-NLS-2$ + } } @@ -791,12 +810,13 @@ private void processBundle(Attributes attributes) { // We need to have id and version, or the url, or both. if (noURL) { - if (noId || noVersion) + if (noId || noVersion) { internalError( NLS.bind(Messages.DefaultSiteParser_Missing, (new String[] { "url", getState(currentState) }))); //$NON-NLS-1$ - else + } else { // default url urlInfo = PLUGINS + id + '_' + ver; // + } } bundle.setURLString(urlInfo); @@ -816,8 +836,9 @@ private void processBundle(Attributes attributes) { // get label if it exists String label = attributes.getValue("label"); //$NON-NLS-1$ if (label != null) { - if ("".equals(label.trim())) //$NON-NLS-1$ + if ("".equals(label.trim())) { //$NON-NLS-1$ label = null; + } checkTranslated(label); } bundle.setLabel(label); @@ -848,8 +869,9 @@ private void processBundle(Attributes attributes) { objectStack.push(bundle); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End Processing DefaultFeature Tag: url:" + urlInfo + " type:" + type); //$NON-NLS-1$ //$NON-NLS-2$ + } } @@ -861,8 +883,9 @@ private void processInfo(Attributes attributes) { String infoURL = attributes.getValue("url"); //$NON-NLS-1$ inf.setURL(infoURL); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("Processed Info: url:" + infoURL); //$NON-NLS-1$ + } objectStack.push(inf); } @@ -910,8 +933,9 @@ private void processSite(Attributes attributes) { } String digestURL = attributes.getValue("digestURL"); //$NON-NLS-1$ - if (digestURL != null) + if (digestURL != null) { site.setDigestURIString(digestURL); + } // TODO: Digest locales // if ((attributes.getValue("availableLocales") != null) && @@ -938,8 +962,9 @@ private void processSite(Attributes attributes) { objectStack.push(site); - if (Tracing.DEBUG_GENERATOR_PARSING) + if (Tracing.DEBUG_GENERATOR_PARSING) { debug("End process Site tag: siteURL:" + siteURL + " type:" + type);//$NON-NLS-1$ //$NON-NLS-2$ + } } @@ -1004,8 +1029,9 @@ public void startElement(String uri, String localName, String qName, Attributes break; } int newState = stateStack.peek().intValue(); - if (newState != STATE_IGNORED_ELEMENT) + if (newState != STATE_IGNORED_ELEMENT) { currentState = newState; + } } @@ -1019,7 +1045,8 @@ private boolean trailingSpace(String str) { // Add translatable strings from the site.xml // to the list of message keys. private void checkTranslated(String value) { - if (value != null && value.length() > 1 && value.startsWith("%")) //$NON-NLS-1$ + if (value != null && value.length() > 1 && value.startsWith("%")) { //$NON-NLS-1$ messageKeys.add(value.substring(1)); + } } } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DigestParser.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DigestParser.java index 1265bca63b..b49a9dc919 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DigestParser.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/DigestParser.java @@ -68,24 +68,28 @@ public void endElement(String uri, String localName, String qName) throws SAXExc if ("feature".equals(localName)) { //$NON-NLS-1$ Feature feature = featureHandler.getResult(); features.add(feature); - } else + } else { featureHandler.endElement(uri, localName, qName); + } } public Feature[] parse(File localFile, URI location) { - if (!localFile.exists()) + if (!localFile.exists()) { return null; + } - if (location == null) + if (location == null) { location = localFile.toURI(); + } JarFile jar = null; InputStream is = null; try { jar = new JarFile(localFile); JarEntry entry = jar.getJarEntry("digest.xml"); //$NON-NLS-1$ - if (entry == null) + if (entry == null) { return null; + } is = new BufferedInputStream(jar.getInputStream(entry)); parser.parse(new InputSource(is), this); return features.toArray(new Feature[features.size()]); @@ -95,14 +99,16 @@ public Feature[] parse(File localFile, URI location) { LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingDigest, location), e)); } finally { try { - if (is != null) + if (is != null) { is.close(); + } } catch (IOException e1) { // } try { - if (jar != null) + if (jar != null) { jar.close(); + } } catch (IOException e) { // } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java index 59062c50ac..3dec29ddd1 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/LocalUpdateSiteAction.java @@ -71,12 +71,14 @@ public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressM IPublisherAction[] actions = createActions(); MultiStatus finalStatus = new MultiStatus(LocalUpdateSiteAction.class.getName(), 0, NLS.bind(Messages.Error_Generation, source != null ? source : (updateSite != null ? updateSite.getLocation().toString() : "Unknown")), null); //$NON-NLS-1$ for (IPublisherAction action : actions) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return Status.CANCEL_STATUS; + } finalStatus.merge(action.perform(info, results, monitor)); } - if (!finalStatus.isOK()) + if (!finalStatus.isOK()) { return finalStatus; + } return Status.OK_STATUS; } @@ -92,13 +94,14 @@ protected IPublisherAction[] createActions() { private IPublisherAction createSiteXMLAction() { SiteXMLAction action = null; - if (updateSite != null) + if (updateSite != null) { action = new SiteXMLAction(updateSite, categoryQualifier); - else if (source != null) { + } else if (source != null) { action = new SiteXMLAction(new File(source, "site.xml").toURI(), categoryQualifier); //$NON-NLS-1$ } - if (action != null && categoryVersion != null) + if (action != null && categoryVersion != null) { action.setCategoryVersion(categoryVersion); + } return action; } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java index 65309e4ec0..ffef68cff0 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/RemoteUpdateSiteAction.java @@ -44,19 +44,23 @@ public RemoteUpdateSiteAction(UpdateSite updateSite, String categoryQualifier) { @Override public IStatus perform(IPublisherInfo info, IPublisherResult results, IProgressMonitor monitor) { - if (Tracing.DEBUG_PUBLISHING) + if (Tracing.DEBUG_PUBLISHING) { Tracing.debug("Generating metadata for update site: " + updateSite.getLocation()); //$NON-NLS-1$ + } IPublisherAction[] actions = createActions(); MultiStatus finalStatus = new MultiStatus(this.getClass().getName(), 0, NLS.bind(Messages.Error_Generation, updateSite != null ? updateSite.getLocation().toString() : "Unknown"), null); //$NON-NLS-1$ for (IPublisherAction action : actions) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return Status.CANCEL_STATUS; + } finalStatus.merge(action.perform(info, results, monitor)); } - if (Tracing.DEBUG_PUBLISHING) + if (Tracing.DEBUG_PUBLISHING) { Tracing.debug("Generation for update site complete: " + updateSite.getLocation()); //$NON-NLS-1$ - if (!finalStatus.isOK()) + } + if (!finalStatus.isOK()) { return finalStatus; + } return Status.OK_STATUS; } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteBundle.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteBundle.java index eb3a06ca9f..960a69c3ad 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteBundle.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteBundle.java @@ -42,10 +42,12 @@ public class SiteBundle { * Compares two URL for equality */ public static boolean sameURL(URL url1, URL url2) { - if (url1 == url2) + if (url1 == url2) { return true; - if (url1 == null ^ url2 == null) + } + if (url1 == null ^ url2 == null) { return false; + } // check if URL are file: URL as we may // have 2 URL pointing to the same bundleReference @@ -60,8 +62,9 @@ public static boolean sameURL(URL url1, URL url2) { } // URL1 xor URL2 is a file, return false. (They either both need to be files, or // neither) - if (isFile1 ^ isFile2) + if (isFile1 ^ isFile2) { return false; + } return getExternalForm(url1).equals(getExternalForm(url2)); } @@ -71,8 +74,9 @@ public static boolean sameURL(URL url1, URL url2) { */ private static String getExternalForm(URL url) { String externalForm = url.toExternalForm(); - if (externalForm == null) + if (externalForm == null) { return ""; //$NON-NLS-1$ + } externalForm = externalForm.trim(); if (externalForm.endsWith("/")) { //$NON-NLS-1$ // Remove the trailing slash @@ -96,17 +100,20 @@ public SiteBundle() { * @param categoryName category name */ public void addCategoryName(String categoryName) { - if (this.categoryNames == null) + if (this.categoryNames == null) { this.categoryNames = new ArrayList<>(); - if (!this.categoryNames.contains(categoryName)) + } + if (!this.categoryNames.contains(categoryName)) { this.categoryNames.add(categoryName); + } } private void delayedResolve() { // PERF: delay resolution - if (resolved) + if (resolved) { return; + } // resolve local elements try { @@ -125,26 +132,34 @@ private void delayedResolve() { */ @Override public boolean equals(Object object) { - if (object == null) + if (object == null) { return false; - if (!(object instanceof SiteBundle)) + } + if (!(object instanceof SiteBundle)) { return false; + } SiteBundle that = (SiteBundle) object; if (this.bundleId == null) { - if (that.bundleId != null) + if (that.bundleId != null) { return false; - } else if (!this.bundleId.equals(that.bundleId)) + } + } else if (!this.bundleId.equals(that.bundleId)) { return false; + } if (this.bundleVersion == null) { - if (that.bundleVersion != null) + if (that.bundleVersion != null) { return false; - } else if (!this.bundleVersion.equals(that.bundleVersion)) + } + } else if (!this.bundleVersion.equals(that.bundleVersion)) { return false; + } if (this.label == null) { - if (that.label != null) + if (that.label != null) { return false; - } else if (!this.label.equals(that.label)) + } + } else if (!this.label.equals(that.label)) { return false; + } return sameURL(this.getURL(), that.getURL()); } @@ -154,17 +169,20 @@ public int hashCode() { int result = 1; result = prime * result + (bundleId == null ? 0 : bundleId.hashCode()); result = prime * result + (bundleVersion == null ? 0 : bundleVersion.hashCode()); - if (this.getURL() == null) + if (this.getURL() == null) { return result; + } if ("file".equalsIgnoreCase(getURL().getProtocol())) {//$NON-NLS-1$ // If the URL is a file, then create the HashCode from the file File f = new File(getURL().getFile()); - if (f != null) + if (f != null) { result = prime * result + f.hashCode(); - } else + } + } else { // Otherwise create it from the External form of the URL (in lower case) result = prime * result + getExternalForm(this.getURL()).hashCode(); + } return result; } @@ -174,8 +192,9 @@ public int hashCode() { * @return an array of names, or an empty array. */ public String[] getCategoryNames() { - if (categoryNames == null) + if (categoryNames == null) { return new String[0]; + } return categoryNames.toArray(new String[0]); } @@ -330,10 +349,11 @@ public void setArch(String arch) { * @param categoryNames an array of category names */ public void setCategoryNames(String[] categoryNames) { - if (categoryNames == null) + if (categoryNames == null) { this.categoryNames = null; - else + } else { this.categoryNames = new ArrayList<>(Arrays.asList(categoryNames)); + } } /** @@ -441,8 +461,9 @@ public String toString() { StringBuilder buffer = new StringBuilder(); buffer.append(getClass().toString() + " :"); //$NON-NLS-1$ buffer.append(" at "); //$NON-NLS-1$ - if (url != null) + if (url != null) { buffer.append(url.toExternalForm()); + } return buffer.toString(); } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteCategory.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteCategory.java index d7e92b74ae..684d52e55a 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteCategory.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteCategory.java @@ -47,8 +47,9 @@ public static Comparator getComparator() { */ comp = (cat1, cat2) -> { - if (cat1.equals(cat2)) + if (cat1.equals(cat2)) { return 0; + } return cat1.getName().compareTo(cat2.getName()); }; } @@ -217,8 +218,9 @@ public void addCategoryName(String categoryName) { * @return an array of names, or an empty array. */ public String[] getCategoryNames() { - if (categoryNames == null) + if (categoryNames == null) { return new String[0]; + } return categoryNames.toArray(new String[0]); } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteFeature.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteFeature.java index 1ee4df81ae..cd26d09ce5 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteFeature.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteFeature.java @@ -48,10 +48,12 @@ public class SiteFeature { * Compares two URL for equality */ public static boolean sameURL(URL url1, URL url2) { - if (url1 == url2) + if (url1 == url2) { return true; - if (url1 == null ^ url2 == null) + } + if (url1 == null ^ url2 == null) { return false; + } // check if URL are file: URL as we may // have 2 URL pointing to the same featureReference @@ -66,8 +68,9 @@ public static boolean sameURL(URL url1, URL url2) { } // URL1 xor URL2 is a file, return false. (They either both need to be files, or // neither) - if (isFile1 ^ isFile2) + if (isFile1 ^ isFile2) { return false; + } return getExternalForm(url1).equals(getExternalForm(url2)); } @@ -77,8 +80,9 @@ public static boolean sameURL(URL url1, URL url2) { */ private static String getExternalForm(URL url) { String externalForm = url.toExternalForm(); - if (externalForm == null) + if (externalForm == null) { return ""; //$NON-NLS-1$ + } externalForm = externalForm.trim(); if (externalForm.endsWith("/")) { //$NON-NLS-1$ // Remove the trailing slash @@ -102,17 +106,20 @@ public SiteFeature() { * @param categoryName category name */ public void addCategoryName(String categoryName) { - if (this.categoryNames == null) + if (this.categoryNames == null) { this.categoryNames = new ArrayList<>(); - if (!this.categoryNames.contains(categoryName)) + } + if (!this.categoryNames.contains(categoryName)) { this.categoryNames.add(categoryName); + } } private void delayedResolve() { // PERF: delay resolution - if (resolved) + if (resolved) { return; + } // resolve local elements try { @@ -131,26 +138,34 @@ private void delayedResolve() { */ @Override public boolean equals(Object object) { - if (object == null) + if (object == null) { return false; - if (!(object instanceof SiteFeature)) + } + if (!(object instanceof SiteFeature)) { return false; + } SiteFeature that = (SiteFeature) object; if (this.featureId == null) { - if (that.featureId != null) + if (that.featureId != null) { return false; - } else if (!this.featureId.equals(that.featureId)) + } + } else if (!this.featureId.equals(that.featureId)) { return false; + } if (this.featureVersion == null) { - if (that.featureVersion != null) + if (that.featureVersion != null) { return false; - } else if (!this.featureVersion.equals(that.featureVersion)) + } + } else if (!this.featureVersion.equals(that.featureVersion)) { return false; + } if (this.label == null) { - if (that.label != null) + if (that.label != null) { return false; - } else if (!this.label.equals(that.label)) + } + } else if (!this.label.equals(that.label)) { return false; + } return sameURL(this.getURL(), that.getURL()); } @@ -160,17 +175,20 @@ public int hashCode() { int result = 1; result = prime * result + (featureId == null ? 0 : featureId.hashCode()); result = prime * result + (featureVersion == null ? 0 : featureVersion.hashCode()); - if (this.getURL() == null) + if (this.getURL() == null) { return result; + } if ("file".equalsIgnoreCase(getURL().getProtocol())) {//$NON-NLS-1$ // If the URL is a file, then create the HashCode from the file File f = new File(getURL().getFile()); - if (f != null) + if (f != null) { result = prime * result + f.hashCode(); - } else + } + } else { // Otherwise create it from the External form of the URL (in lower case) result = prime * result + getExternalForm(this.getURL()).hashCode(); + } return result; } @@ -180,8 +198,9 @@ public int hashCode() { * @return an array of names, or an empty array. */ public String[] getCategoryNames() { - if (categoryNames == null) + if (categoryNames == null) { return new String[0]; + } return categoryNames.toArray(new String[0]); } @@ -336,10 +355,11 @@ public void setArch(String arch) { * @param categoryNames an array of category names */ public void setCategoryNames(String[] categoryNames) { - if (categoryNames == null) + if (categoryNames == null) { this.categoryNames = null; - else + } else { this.categoryNames = new ArrayList<>(Arrays.asList(categoryNames)); + } } /** @@ -445,10 +465,12 @@ public void setWS(String ws) { @Override public String toString() { StringBuilder buffer = new StringBuilder(); - if (featureId != null) + if (featureId != null) { buffer.append(featureId).append(' '); - if (featureVersion != null) + } + if (featureVersion != null) { buffer.append(featureVersion).append(' '); + } if (url != null) { buffer.append(" at "); //$NON-NLS-1$ buffer.append(url.toExternalForm()); diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteIU.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteIU.java index 0fe399f749..c79ec5f880 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteIU.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteIU.java @@ -68,8 +68,9 @@ public String getQueryType() { * @return an array of query params. */ public String[] getQueryParams() { - if (queryParams == null) + if (queryParams == null) { return new String[0]; + } return queryParams.toArray(new String[0]); } @@ -80,8 +81,9 @@ public String[] getQueryParams() { * @return an array of names, or an empty array. */ public String[] getCategoryNames() { - if (categoryNames == null) + if (categoryNames == null) { return new String[0]; + } return categoryNames.toArray(new String[0]); } @@ -126,10 +128,12 @@ public void setQueryType(String queryType) { * @param categoryName category name */ public void addCategoryName(String categoryName) { - if (this.categoryNames == null) + if (this.categoryNames == null) { this.categoryNames = new ArrayList<>(); - if (!this.categoryNames.contains(categoryName)) + } + if (!this.categoryNames.contains(categoryName)) { this.categoryNames.add(categoryName); + } } /** @@ -138,8 +142,9 @@ public void addCategoryName(String categoryName) { * @param queryParam a query param. */ public void addQueryParams(String queryParam) { - if (this.queryParams == null) + if (this.queryParams == null) { this.queryParams = new ArrayList<>(); + } // don't do contains check, order matters and there may be duplicates this.queryParams.add(queryParam); } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java index daeb920247..d6ae74e53f 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteModel.java @@ -73,10 +73,12 @@ public SiteModel() { * @since 2.0 */ public void addArchive(URLEntry archiveReference) { - if (this.archiveReferences == null) + if (this.archiveReferences == null) { this.archiveReferences = new ArrayList<>(); - if (!this.archiveReferences.contains(archiveReference)) + } + if (!this.archiveReferences.contains(archiveReference)) { this.archiveReferences.add(archiveReference); + } } /** @@ -85,12 +87,14 @@ public void addArchive(URLEntry archiveReference) { * @param category category model */ public void addCategory(SiteCategory category) { - if (categories == null) + if (categories == null) { categories = new HashMap<>(); + } if (!categories.containsKey(category.getName())) { categories.put(category.getName(), category); - if (localizations != null && !localizations.isEmpty()) + if (localizations != null && !localizations.isEmpty()) { category.setLocalizations(localizations); + } } } @@ -100,8 +104,9 @@ public void addCategory(SiteCategory category) { * @param featureReference feature reference model */ public void addFeature(SiteFeature featureReference) { - if (this.features == null) + if (this.features == null) { this.features = new ArrayList<>(); + } this.features.add(featureReference); } @@ -111,8 +116,9 @@ public void addFeature(SiteFeature featureReference) { * @param bundleReference bundle reference model */ public void addBundle(SiteBundle bundleReference) { - if (this.bundles == null) + if (this.bundles == null) { this.bundles = new ArrayList<>(); + } this.bundles.add(bundleReference); } @@ -122,8 +128,9 @@ public void addBundle(SiteBundle bundleReference) { * @param featureReference feature reference model */ public void addStatsFeature(SiteFeature featureReference) { - if (this.statsFeatures == null) + if (this.statsFeatures == null) { this.statsFeatures = new ArrayList<>(); + } this.statsFeatures.add(featureReference); } @@ -133,8 +140,9 @@ public void addStatsFeature(SiteFeature featureReference) { * @param bundleReference bundle reference model */ public void addStatsBundle(SiteBundle bundleReference) { - if (this.statsBundles == null) + if (this.statsBundles == null) { this.statsBundles = new ArrayList<>(); + } this.statsBundles.add(bundleReference); } @@ -144,8 +152,9 @@ public void addStatsBundle(SiteBundle bundleReference) { * @param iu iu model */ public void addIU(SiteIU iu) { - if (this.ius == null) + if (this.ius == null) { this.ius = new ArrayList<>(); + } this.ius.add(iu); } @@ -155,8 +164,9 @@ public void addIU(SiteIU iu) { * @param ref repository reference */ public void addRepositoryReference(RepositoryReference ref) { - if (this.repositoryReferences == null) + if (this.repositoryReferences == null) { this.repositoryReferences = new ArrayList<>(); + } this.repositoryReferences.add(ref); } @@ -169,8 +179,9 @@ public void addRepositoryReference(RepositoryReference ref) { * @since 2.0 */ public URLEntry[] getArchives() { - if (archiveReferences == null || archiveReferences.size() == 0) + if (archiveReferences == null || archiveReferences.size() == 0) { return new URLEntry[0]; + } return archiveReferences.toArray(new URLEntry[0]); } @@ -186,8 +197,9 @@ public URLEntry[] getAssociatedSites() { * @since 2.0 */ public SiteCategory[] getCategories() { - if (categories == null || categories.size() == 0) + if (categories == null || categories.size() == 0) { return new SiteCategory[0]; + } return categories.values().toArray(new SiteCategory[0]); } @@ -215,8 +227,9 @@ public URLEntry getDescription() { * @return an array of feature reference models, or an empty array. */ public SiteFeature[] getFeatures() { - if (features == null || features.size() == 0) + if (features == null || features.size() == 0) { return new SiteFeature[0]; + } return features.toArray(new SiteFeature[0]); } @@ -226,8 +239,9 @@ public SiteFeature[] getFeatures() { * @return an array of bundle reference models, or an empty array. */ public SiteBundle[] getBundles() { - if (bundles == null || bundles.size() == 0) + if (bundles == null || bundles.size() == 0) { return new SiteBundle[0]; + } return bundles.toArray(new SiteBundle[0]); } @@ -237,8 +251,9 @@ public SiteBundle[] getBundles() { * @return an array of feature reference models, or an empty array. */ public SiteFeature[] getStatsFeatures() { - if (statsFeatures == null || statsFeatures.size() == 0) + if (statsFeatures == null || statsFeatures.size() == 0) { return new SiteFeature[0]; + } return statsFeatures.toArray(new SiteFeature[0]); } @@ -248,8 +263,9 @@ public SiteFeature[] getStatsFeatures() { * @return an array of bundle reference models, or an empty array. */ public SiteBundle[] getStatsBundles() { - if (statsBundles == null || statsBundles.size() == 0) + if (statsBundles == null || statsBundles.size() == 0) { return new SiteBundle[0]; + } return statsBundles.toArray(new SiteBundle[0]); } @@ -259,8 +275,9 @@ public SiteBundle[] getStatsBundles() { * @return an array of IU models, or an empty array. */ public SiteIU[] getIUs() { - if (ius == null || ius.size() == 0) + if (ius == null || ius.size() == 0) { return new SiteIU[0]; + } return ius.toArray(new SiteIU[0]); } @@ -270,8 +287,9 @@ public SiteIU[] getIUs() { * @return an array of repository references, or an empty array. */ public RepositoryReference[] getRepositoryReferences() { - if (repositoryReferences == null || repositoryReferences.size() == 0) + if (repositoryReferences == null || repositoryReferences.size() == 0) { return new RepositoryReference[0]; + } return repositoryReferences.toArray(new RepositoryReference[repositoryReferences.size()]); } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java index ef524d7c09..8f8f88b897 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/SiteXMLAction.java @@ -94,8 +94,9 @@ public void setCategoryVersion(String version) { } private void initialize() { - if (defaultCategory != null) + if (defaultCategory != null) { return; + } defaultCategory = new SiteCategory(); defaultCategory.setDescription("Default category for otherwise uncategorized features"); //$NON-NLS-1$ defaultCategory.setLabel("Uncategorized"); //$NON-NLS-1$ @@ -134,8 +135,9 @@ private IStatus markStatsArtifacts(IPublisherInfo publisherInfo, IPublisherResul SiteFeature[] features = site.getStatsFeatures(); if (features != null && artifactRepo != null) { for (SiteFeature feature : features) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return Status.CANCEL_STATUS; + } Collection ius = getFeatureIU(feature, publisherInfo, results); if (ius != null) { for (IInstallableUnit iu : ius) { @@ -155,8 +157,9 @@ private IStatus markStatsArtifacts(IPublisherInfo publisherInfo, IPublisherResul SiteBundle[] bundles = site.getStatsBundles(); if (bundles != null && artifactRepo != null) { for (SiteBundle bundle : bundles) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return Status.CANCEL_STATUS; + } Collection ius = getBundleIU(bundle, publisherInfo, results); if (ius != null) { for (IInstallableUnit iu : ius) { @@ -177,9 +180,10 @@ private IStatus markStatsArtifacts(IPublisherInfo publisherInfo, IPublisherResul // a warning. boolean markingBundles = bundles != null && bundles.length > 0; boolean markingFeatures = features != null && features.length > 0; - if (artifactRepo == null && (markingBundles || markingFeatures)) + if (artifactRepo == null && (markingBundles || markingFeatures)) { return new Status(IStatus.WARNING, Activator.ID, "Artifact repository was not specified so stats properties could not be published."); //$NON-NLS-1$ + } return Status.OK_STATUS; } @@ -189,16 +193,19 @@ private IStatus generateCategories(IPublisherInfo publisherInfo, IPublisherResul Map> categoriesToIUs = new HashMap<>(); Map> featuresToCategories = getFeatureToCategoryMappings(publisherInfo); for (SiteFeature feature : featuresToCategories.keySet()) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return Status.CANCEL_STATUS; + } Collection ius = getFeatureIU(feature, publisherInfo, results); - if (ius == null) + if (ius == null) { continue; + } Set categories = featuresToCategories.get(feature); // if there are no categories for this feature then add it to the default // category. - if (categories == null || categories.isEmpty()) + if (categories == null || categories.isEmpty()) { categories = defaultCategorySet; + } for (SiteCategory category : categories) { Set iusInCategory = categoriesToIUs.get(category); if (iusInCategory == null) { @@ -211,16 +218,19 @@ private IStatus generateCategories(IPublisherInfo publisherInfo, IPublisherResul // Bundles -- bug 378338 Map> bundlesToCategories = getBundleToCategoryMappings(publisherInfo); for (SiteBundle bundle : bundlesToCategories.keySet()) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { return Status.CANCEL_STATUS; + } Collection ius = getBundleIU(bundle, publisherInfo, results); - if (ius == null) + if (ius == null) { continue; + } Set categories = bundlesToCategories.get(bundle); // if there are no categories for this feature then add it to the default // category. - if (categories == null || categories.isEmpty()) + if (categories == null || categories.isEmpty()) { categories = defaultCategorySet; + } for (SiteCategory category : categories) { Set iusInCategory = categoriesToIUs.get(category); if (iusInCategory == null) { @@ -240,18 +250,21 @@ private void addSiteIUsToCategories(Map> cat IPublisherInfo publisherInfo, IPublisherResult results) { Map> iusToCategories = getIUToCategoryMappings(publisherInfo); SiteModel site = updateSite.getSite(); - if (site == null) + if (site == null) { return; + } SiteIU[] siteIUs = site.getIUs(); for (SiteIU siteIU : siteIUs) { Collection ius = getIUs(siteIU, publisherInfo, results); - if (ius == null) + if (ius == null) { continue; + } Set categories = iusToCategories.get(siteIU); // if there are no categories for this feature then add it to the default // category. - if (categories == null || categories.isEmpty()) + if (categories == null || categories.isEmpty()) { categories = defaultCategorySet; + } for (SiteCategory category : categories) { Set iusInCategory = categoriesToIUs.get(category); if (iusInCategory == null) { @@ -265,11 +278,13 @@ private void addSiteIUsToCategories(Map> cat private Map> getIUToCategoryMappings(IPublisherInfo publisherInfo) { HashMap> mappings = new HashMap<>(); - if (updateSite == null) + if (updateSite == null) { return mappings; + } SiteModel site = updateSite.getSite(); - if (site == null) + if (site == null) { return mappings; + } SiteIU[] ius = site.getIUs(); for (SiteIU iu : ius) { @@ -279,8 +294,9 @@ private Map> getIUToCategoryMappings(IPublisherInfo pu mappings.put(iu, categories); for (String categoryName : categoryNames) { SiteCategory category = site.getCategory(categoryName); - if (category != null) + if (category != null) { categories.add(category); + } } } return mappings; @@ -293,23 +309,28 @@ private Collection getIUs(SiteIU siteIU, IPublisherInfo publis String type = siteIU.getQueryType(); String expression = siteIU.getQueryExpression(); Object[] params = siteIU.getQueryParams(); - if (id == null && (type == null || expression == null)) + if (id == null && (type == null || expression == null)) { return Collections.emptyList(); + } IQuery query = null; if (id != null) { VersionRange vRange = VersionRange.create(range); query = QueryUtil.createIUQuery(id, vRange); } else if (type.equals("context")) { //$NON-NLS-1$ query = QueryUtil.createQuery(expression, params); - } else if (type.equals("match")) //$NON-NLS-1$ + } else if (type.equals("match")) { //$NON-NLS-1$ query = QueryUtil.createMatchQuery(expression, params); - if (query == null) + } + if (query == null) { return Collections.emptyList(); + } IQueryResult queryResult = results.query(query, null); - if (queryResult.isEmpty()) + if (queryResult.isEmpty()) { queryResult = publisherInfo.getMetadataRepository().query(query, null); - if (queryResult.isEmpty() && publisherInfo.getContextMetadataRepository() != null) + } + if (queryResult.isEmpty() && publisherInfo.getContextMetadataRepository() != null) { queryResult = publisherInfo.getContextMetadataRepository().query(query, null); + } return queryResult.toUnmodifiableSet(); } @@ -342,13 +363,16 @@ private Collection getFeatureIU(SiteFeature feature, IPublishe } IQueryResult queryResult = results.query(query, null); - if (queryResult.isEmpty()) + if (queryResult.isEmpty()) { queryResult = publisherInfo.getMetadataRepository().query(query, null); - if (queryResult.isEmpty() && publisherInfo.getContextMetadataRepository() != null) + } + if (queryResult.isEmpty() && publisherInfo.getContextMetadataRepository() != null) { queryResult = publisherInfo.getContextMetadataRepository().query(query, null); + } - if (!queryResult.isEmpty()) + if (!queryResult.isEmpty()) { return queryResult.toUnmodifiableSet(); + } return null; } @@ -378,38 +402,43 @@ private Collection getBundleIU(SiteBundle bundle, IPublisherIn } IQueryResult queryResult = results.query(query, null); - if (queryResult.isEmpty()) + if (queryResult.isEmpty()) { queryResult = publisherInfo.getMetadataRepository().query(query, null); - if (queryResult.isEmpty() && publisherInfo.getContextMetadataRepository() != null) + } + if (queryResult.isEmpty() && publisherInfo.getContextMetadataRepository() != null) { queryResult = publisherInfo.getContextMetadataRepository().query(query, null); + } - if (!queryResult.isEmpty()) + if (!queryResult.isEmpty()) { return queryResult.toUnmodifiableSet(); + } return null; } protected VersionRange createVersionRange(String versionId) { VersionRange range = null; - if (versionId == null || "0.0.0".equals(versionId)) //$NON-NLS-1$ + if (versionId == null || "0.0.0".equals(versionId)) { //$NON-NLS-1$ range = VersionRange.emptyRange; - else { + } else { int qualifierIdx = versionId.indexOf(QUALIFIER); if (qualifierIdx != -1) { String newVersion = versionId.substring(0, qualifierIdx); - if (newVersion.endsWith(".")) //$NON-NLS-1$ + if (newVersion.endsWith(".")) { //$NON-NLS-1$ newVersion = newVersion.substring(0, newVersion.length() - 1); + } Version lower = Version.parseVersion(newVersion); Version upper = null; String newQualifier = VersionSuffixGenerator .incrementQualifier(PublisherHelper.toOSGiVersion(lower).getQualifier()); org.osgi.framework.Version osgiVersion = PublisherHelper.toOSGiVersion(lower); - if (newQualifier == null) + if (newQualifier == null) { upper = Version.createOSGi(osgiVersion.getMajor(), osgiVersion.getMinor(), osgiVersion.getMicro() + 1); - else + } else { upper = Version.createOSGi(osgiVersion.getMajor(), osgiVersion.getMinor(), osgiVersion.getMicro(), newQualifier); + } range = new VersionRange(lower, true, upper, false); } else { range = new VersionRange(Version.parseVersion(versionId), true, Version.parseVersion(versionId), true); @@ -426,11 +455,13 @@ protected VersionRange createVersionRange(String versionId) { */ protected Map> getFeatureToCategoryMappings(IPublisherInfo publisherInfo) { HashMap> mappings = new HashMap<>(); - if (updateSite == null) + if (updateSite == null) { return mappings; + } SiteModel site = updateSite.getSite(); - if (site == null) + if (site == null) { return mappings; + } SiteFeature[] features = site.getFeatures(); for (SiteFeature feature : features) { @@ -443,8 +474,9 @@ protected Map> getFeatureToCategoryMappings(IPubl } for (String categoryName : categoryNames) { SiteCategory category = site.getCategory(categoryName); - if (category != null) + if (category != null) { categories.add(category); + } } } return mappings; @@ -458,11 +490,13 @@ protected Map> getFeatureToCategoryMappings(IPubl */ protected Map> getBundleToCategoryMappings(IPublisherInfo publisherInfo) { HashMap> mappings = new HashMap<>(); - if (updateSite == null) + if (updateSite == null) { return mappings; + } SiteModel site = updateSite.getSite(); - if (site == null) + if (site == null) { return mappings; + } SiteBundle[] bundles = site.getBundles(); for (SiteBundle bundle : bundles) { @@ -472,8 +506,9 @@ protected Map> getBundleToCategoryMappings(IPublis mappings.put(bundle, categories); for (String categoryName : categoryNames) { SiteCategory category = site.getCategory(categoryName); - if (category != null) + if (category != null) { categories.add(category); + } } } return mappings; @@ -492,13 +527,15 @@ private void initializeRepoFromSite(IPublisherInfo publisherInfo) { if (mirrors != null) { // remove site.xml file reference int index = mirrors.indexOf("site.xml"); //$NON-NLS-1$ - if (index != -1) + if (index != -1) { mirrors = mirrors.substring(0, index) + mirrors.substring(index + "site.xml".length()); //$NON-NLS-1$ + } publisherInfo.getMetadataRepository().setProperty(IRepository.PROP_MIRRORS_URL, mirrors); // there does not really need to be an artifact repo but if there is, setup its // mirrors. - if (publisherInfo.getArtifactRepository() != null) + if (publisherInfo.getArtifactRepository() != null) { publisherInfo.getArtifactRepository().setProperty(IRepository.PROP_MIRRORS_URL, mirrors); + } } // publish associate sites as repository references @@ -532,8 +569,9 @@ private void initializeRepoFromSite(IPublisherInfo publisherInfo) { // publish download stats URL from category file String statsURI = site.getStatsURI(); if (statsURI != null && statsURI.length() > 0) { - if (publisherInfo.getArtifactRepository() != null) + if (publisherInfo.getArtifactRepository() != null) { publisherInfo.getArtifactRepository().setProperty(P_STATS_URI, statsURI); + } } File siteFile = URIUtil.toFile(updateSite.getLocation()); @@ -677,10 +715,10 @@ public IInstallableUnit createCategoryIU(SiteCategory category, Set 0) + if (categoryQualifier.length() > 0) { return categoryQualifier + "." + categoryName; //$NON-NLS-1$ + } return categoryName; } - if (updateSite != null) + if (updateSite != null) { return URIUtil.toUnencodedString(updateSite.getLocation()) + "." + categoryName; //$NON-NLS-1$ + } return categoryName; } protected Transport getTransport(IPublisherInfo publisherInfo) { IRepository repo = publisherInfo.getMetadataRepository(); - if (repo == null) + if (repo == null) { repo = publisherInfo.getArtifactRepository(); - if (repo == null) + } + if (repo == null) { throw new IllegalStateException("The transport service can not be found."); //$NON-NLS-1$ + } return repo.getProvisioningAgent().getService(Transport.class); } } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java index d36746df74..70d56b2ad4 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSite.java @@ -68,8 +68,9 @@ public class UpdateSite { */ private static URI getSiteURI(URI baseLocation) { String segment = URIUtil.lastSegment(baseLocation); - if (constainsUpdateSiteFileName(segment)) + if (constainsUpdateSiteFileName(segment)) { return baseLocation; + } return URIUtil.append(baseLocation, SITE_FILE); } @@ -87,13 +88,15 @@ private static boolean constainsUpdateSiteFileName(String segment) { */ public static synchronized UpdateSite loadCategoryFile(URI location, Transport transport, IProgressMonitor monitor) throws ProvisionException { - if (location == null) + if (location == null) { return null; + } UpdateSite result = null; if (!PROTOCOL_FILE.equals(location.getScheme()) && categoryCache.containsKey(location.toString())) { result = categoryCache.get(location.toString()).get(); - if (result != null) + if (result != null) { return result; + } // else soft reference has been cleared, take it out of the cache categoryCache.remove(location.toString()); } @@ -107,8 +110,9 @@ public static synchronized UpdateSite loadCategoryFile(URI location, Transport t SiteModel siteModel = siteParser.parse(input); String checksumString = Long.toString(checksum.getValue()); result = new UpdateSite(siteModel, location, transport, checksumString); - if (!PROTOCOL_FILE.equals(location.getScheme())) + if (!PROTOCOL_FILE.equals(location.getScheme())) { categoryCache.put(location.toString(), new SoftReference<>(result)); + } return result; } catch (SAXException e) { String msg = NLS.bind(Messages.ErrorReadingSite, location); @@ -120,13 +124,15 @@ public static synchronized UpdateSite loadCategoryFile(URI location, Transport t new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); } finally { try { - if (input != null) + if (input != null) { input.close(); + } } catch (IOException e) { // ignore } - if (!PROTOCOL_FILE.equals(location.getScheme())) + if (!PROTOCOL_FILE.equals(location.getScheme())) { siteFile.delete(); + } } } @@ -135,15 +141,17 @@ public static synchronized UpdateSite loadCategoryFile(URI location, Transport t */ public static synchronized UpdateSite load(URI location, Transport transport, IProgressMonitor monitor) throws ProvisionException { - if (location == null) + if (location == null) { return null; + } UpdateSite result = null; // only caching remote sites if (!PROTOCOL_FILE.equals(location.getScheme()) && siteCache.containsKey(location.toString())) { result = siteCache.get(location.toString()).get(); - if (result != null) + if (result != null) { return result; + } // else soft reference has been cleared, take it out of the cache siteCache.remove(location.toString()); } @@ -157,8 +165,9 @@ public static synchronized UpdateSite load(URI location, Transport transport, IP SiteModel siteModel = siteParser.parse(input); String checksumString = Long.toString(checksum.getValue()); result = new UpdateSite(siteModel, getSiteURI(location), transport, checksumString); - if (!PROTOCOL_FILE.equals(location.getScheme())) + if (!PROTOCOL_FILE.equals(location.getScheme())) { siteCache.put(location.toString(), new SoftReference<>(result)); + } return result; } catch (SAXException e) { String msg = NLS.bind(Messages.ErrorReadingSite, location); @@ -170,13 +179,15 @@ public static synchronized UpdateSite load(URI location, Transport transport, IP new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, e)); } finally { try { - if (input != null) + if (input != null) { input.close(); + } } catch (IOException e) { // ignore } - if (!PROTOCOL_FILE.equals(location.getScheme())) + if (!PROTOCOL_FILE.equals(location.getScheme())) { siteFile.delete(); + } } } @@ -194,9 +205,9 @@ private static File loadActualSiteFile(URI location, URI actualLocation, Transpo try { if (PROTOCOL_FILE.equals(actualLocation.getScheme())) { siteFile = URIUtil.toFile(actualLocation); - if (siteFile.exists()) + if (siteFile.exists()) { transferResult = Status.OK_STATUS; - else { + } else { String msg = NLS.bind(Messages.ErrorReadingSite, location); transferResult = new Status(IStatus.ERROR, Activator.ID, ProvisionException.ARTIFACT_NOT_FOUND, msg, new FileNotFoundException(siteFile.getAbsolutePath())); @@ -223,8 +234,9 @@ private static File loadActualSiteFile(URI location, URI actualLocation, Transpo } } } - if (monitor.isCanceled()) + if (monitor.isCanceled()) { throw new OperationCanceledException(); + } if (transferResult.isOK()) { // successful. If the siteFile is the download of a remote site.xml it will get // cleaned up later @@ -238,7 +250,7 @@ private static File loadActualSiteFile(URI location, URI actualLocation, Transpo // REPOSITORY_NOT_FOUND as the download does not know what the file represents. // IStatus ms = null; - if (transferResult.getException() instanceof FileNotFoundException) + if (transferResult.getException() instanceof FileNotFoundException) { ms = new MultiStatus(Activator.ID, // ProvisionException.REPOSITORY_NOT_FOUND, // (code == ProvisionException.ARTIFACT_NOT_FOUND || code == @@ -247,17 +259,20 @@ private static File loadActualSiteFile(URI location, URI actualLocation, Transpo // ProvisionException.REPOSITORY_FAILED_READ), // new IStatus[] { transferResult }, // NLS.bind(Messages.ErrorReadingSite, location), null); - else + } else { ms = transferResult; + } throw new ProvisionException(ms); } finally { - if (deleteSiteFile && siteFile != null) + if (deleteSiteFile && siteFile != null) { siteFile.delete(); + } } } finally { - if (monitor != null) + if (monitor != null) { monitor.done(); + } } } @@ -277,8 +292,9 @@ private Feature parseFeature(FeatureParser featureParser, URI featureURI, IProgr IStatus transferResult = null; // try the download twice in case of transient network problems for (int i = 0; i < RETRY_COUNT; i++) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { throw new OperationCanceledException(); + } OutputStream destination = new BufferedOutputStream(new FileOutputStream(featureFile)); try { transferResult = transport.download(featureURI, destination, monitor); @@ -291,11 +307,13 @@ private Feature parseFeature(FeatureParser featureParser, URI featureURI, IProgr return null; } } - if (transferResult.isOK()) + if (transferResult.isOK()) { break; + } } - if (monitor.isCanceled()) + if (monitor.isCanceled()) { throw new OperationCanceledException(); + } if (!transferResult.isOK()) { LogHelper.log(new ProvisionException(transferResult)); return null; @@ -305,8 +323,9 @@ private Feature parseFeature(FeatureParser featureParser, URI featureURI, IProgr LogHelper.log( new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingFeature, featureURI), e)); } finally { - if (featureFile != null) + if (featureFile != null) { featureFile.delete(); + } } return null; } @@ -326,8 +345,9 @@ private UpdateSite(SiteModel site, URI location, Transport transport, String che private URI getRootLocation() { String locationString = location.toString(); int slashIndex = locationString.lastIndexOf('/'); - if (slashIndex == -1 || slashIndex == (locationString.length() - 1)) + if (slashIndex == -1 || slashIndex == (locationString.length() - 1)) { return location; + } return URI.create(locationString.substring(0, slashIndex + 1)); } @@ -340,8 +360,9 @@ private URI getArchiveURI(URI base, String identifier) { URLEntry[] archives = site.getArchives(); for (int i = 0; archives != null && i < archives.length; i++) { URLEntry entry = archives[i]; - if (identifier.equals(entry.getAnnotation())) + if (identifier.equals(entry.getAnnotation())) { return internalGetURI(base, entry.getURL()); + } } return null; } @@ -359,8 +380,9 @@ public String getChecksum() { public URI getSiteFeatureURI(SiteFeature siteFeature) { URL url = siteFeature.getURL(); try { - if (url != null) + if (url != null) { return URIUtil.toURI(url); + } } catch (URISyntaxException e) { // fall through and resolve the URI ourselves } @@ -375,8 +397,9 @@ public URI getSiteFeatureURI(SiteFeature siteFeature) { public URI getSiteBundleURI(SiteBundle siteBundle) { URL url = siteBundle.getURL(); try { - if (url != null) + if (url != null) { return URIUtil.toURI(url); + } } catch (URISyntaxException e) { // fall through and resolve the URI ourselves } @@ -398,8 +421,9 @@ public URI getFeatureURI(String id, String version) { URI base = getBaseURI(); URI url = getArchiveURI(base, FEATURE_DIR + id + VERSION_SEPARATOR + version + JAR_EXTENSION); - if (url != null) + if (url != null) { return url; + } return URIUtil.append(base, FEATURE_DIR + id + VERSION_SEPARATOR + version + JAR_EXTENSION); } @@ -416,8 +440,9 @@ public URI getBundleURI(String id, String version) { URI base = getBaseURI(); URI url = getArchiveURI(base, FEATURE_DIR + id + VERSION_SEPARATOR + version + JAR_EXTENSION); - if (url != null) + if (url != null) { return url; + } return URIUtil.append(base, FEATURE_DIR + id + VERSION_SEPARATOR + version + JAR_EXTENSION); } @@ -431,12 +456,14 @@ public URI getLocation() { public String getMirrorsURI() { // copy mirror information from update site to p2 repositories String mirrors = site.getMirrorsURI(); - if (mirrors == null) + if (mirrors == null) { return null; + } // remove site.xml file reference int index = mirrors.indexOf("site.xml"); //$NON-NLS-1$ - if (index != -1) + if (index != -1) { mirrors = mirrors.substring(0, index) + mirrors.substring(index + "site.xml".length()); //$NON-NLS-1$ + } return mirrors; } @@ -447,8 +474,9 @@ public URI getPluginURI(FeatureEntry plugin) { URI base = getBaseURI(); String path = PLUGIN_DIR + plugin.getId() + VERSION_SEPARATOR + plugin.getVersion() + JAR_EXTENSION; URI url = getArchiveURI(base, path); - if (url != null) + if (url != null) { return url; + } return URIUtil.append(base, path); } @@ -456,12 +484,14 @@ private URI getBaseURI() { URI base = null; String siteURIString = site.getLocationURIString(); if (siteURIString != null) { - if (!siteURIString.endsWith("/")) //$NON-NLS-1$ + if (!siteURIString.endsWith("/")) { //$NON-NLS-1$ siteURIString += "/"; //$NON-NLS-1$ + } base = internalGetURI(rootLocation, siteURIString); } - if (base == null) + if (base == null) { base = rootLocation; + } return base; } @@ -478,8 +508,9 @@ public SiteModel getSite() { * it. If it is relative, then make it relative to the given base url. */ private URI internalGetURI(URI base, String trailing) { - if (trailing == null) + if (trailing == null) { return null; + } return URIUtil.makeAbsolute(URI.create(trailing), base); } @@ -487,8 +518,9 @@ private URI internalGetURI(URI base, String trailing) { * Load and return the features references in this update site. */ public synchronized Feature[] loadFeatures(IProgressMonitor monitor) throws ProvisionException { - if (!featureCache.isEmpty()) + if (!featureCache.isEmpty()) { return featureCache.values().toArray(new Feature[featureCache.size()]); + } Feature[] result = loadFeaturesFromDigest(monitor); return result == null ? loadFeaturesFromSite(monitor) : result; } @@ -497,8 +529,9 @@ public synchronized Feature[] loadFeatures(IProgressMonitor monitor) throws Prov * Load and return the bundle references in this update site. */ public synchronized BundleDescription[] loadBundles(IProgressMonitor monitor) { - if (!bundleCache.isEmpty()) + if (!bundleCache.isEmpty()) { return bundleCache.values().toArray(new BundleDescription[bundleCache.size()]); + } BundleDescription[] result = null; // TODO loadBundlesFromDigest(monitor); return result == null ? loadBundlesFromSite(monitor) : result; } @@ -514,8 +547,9 @@ private Feature[] loadFeaturesFromDigest(IProgressMonitor monitor) { URI digestURI = getDigestURI(); if (PROTOCOL_FILE.equals(digestURI.getScheme())) { digestFile = URIUtil.toFile(digestURI); - if (!digestFile.exists()) + if (!digestFile.exists()) { return null; + } local = true; } else { digestFile = File.createTempFile("digest", ".zip"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -532,14 +566,17 @@ private Feature[] loadFeaturesFromDigest(IProgressMonitor monitor) { return null; } } - if (result.getSeverity() == IStatus.CANCEL || monitor.isCanceled()) + if (result.getSeverity() == IStatus.CANCEL || monitor.isCanceled()) { throw new OperationCanceledException(); - if (!result.isOK()) + } + if (!result.isOK()) { return null; + } } Feature[] features = new DigestParser().parse(digestFile, digestURI); - if (features == null) + if (features == null) { return null; + } Map tmpFeatureCache = new HashMap<>(features.length); for (Feature feature : features) { String key = feature.getId() + VERSION_SEPARATOR + feature.getVersion(); @@ -553,8 +590,9 @@ private Feature[] loadFeaturesFromDigest(IProgressMonitor monitor) { } catch (IOException e) { LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingDigest, location), e)); } finally { - if (!local && digestFile != null) + if (!local && digestFile != null) { digestFile.delete(); + } } return null; } @@ -563,13 +601,15 @@ private URI getDigestURI() { URI digestBase = null; String digestURIString = site.getDigestURIString(); if (digestURIString != null) { - if (!digestURIString.endsWith("/")) //$NON-NLS-1$ + if (!digestURIString.endsWith("/")) { //$NON-NLS-1$ digestURIString += "/"; //$NON-NLS-1$ + } digestBase = internalGetURI(rootLocation, digestURIString); } - if (digestBase == null) + if (digestBase == null) { digestBase = rootLocation; + } return URIUtil.append(digestBase, "digest.zip"); //$NON-NLS-1$ } @@ -591,8 +631,9 @@ private Feature[] loadFeaturesFromSite(IProgressMonitor monitor) throws Provisio String key = null; if (siteFeature.getFeatureIdentifier() != null && siteFeature.getFeatureVersion() != null) { key = siteFeature.getFeatureIdentifier() + VERSION_SEPARATOR + siteFeature.getFeatureVersion(); - if (tmpFeatureCache.containsKey(key)) + if (tmpFeatureCache.containsKey(key)) { continue; + } } URI featureURI = getSiteFeatureURI(siteFeature); Feature feature = parseFeature(featureParser, featureURI, new NullProgressMonitor()); @@ -620,14 +661,17 @@ private void loadIncludedFeatures(Feature feature, FeatureParser featureParser, IProgressMonitor monitor) throws ProvisionException { FeatureEntry[] featureEntries = feature.getEntries(); for (FeatureEntry featureEntry : featureEntries) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { throw new OperationCanceledException(); + } FeatureEntry entry = featureEntry; - if (entry.isRequires() || entry.isPlugin()) + if (entry.isRequires() || entry.isPlugin()) { continue; + } String key = entry.getId() + VERSION_SEPARATOR + entry.getVersion(); - if (features.containsKey(key)) + if (features.containsKey(key)) { continue; + } URI includedFeatureURI = getFeatureURI(entry.getId(), entry.getVersion()); Feature includedFeature = parseFeature(featureParser, includedFeatureURI, monitor); if (includedFeature == null) { @@ -655,8 +699,9 @@ private BundleDescription[] loadBundlesFromSite(IProgressMonitor monitor) { String key = null; if (siteBundle.getBundleIdentifier() != null && siteBundle.getBundleVersion() != null) { key = siteBundle.getBundleIdentifier() + VERSION_SEPARATOR + siteBundle.getBundleVersion(); - if (tmpBundleCache.containsKey(key)) + if (tmpBundleCache.containsKey(key)) { continue; + } } URI bundleURI = getSiteBundleURI(siteBundle); BundleDescription bundle = parseBundleDescription(bundleURI, monitor); @@ -691,8 +736,9 @@ private BundleDescription parseBundleDescription(URI bundleURI, IProgressMonitor IStatus transferResult = null; // try the download twice in case of transient network problems for (int i = 0; i < RETRY_COUNT; i++) { - if (monitor.isCanceled()) + if (monitor.isCanceled()) { throw new OperationCanceledException(); + } OutputStream destination = new BufferedOutputStream(new FileOutputStream(bundleFile)); try { transferResult = transport.download(bundleURI, destination, monitor); @@ -705,11 +751,13 @@ private BundleDescription parseBundleDescription(URI bundleURI, IProgressMonitor return null; } } - if (transferResult.isOK()) + if (transferResult.isOK()) { break; + } } - if (monitor.isCanceled()) + if (monitor.isCanceled()) { throw new OperationCanceledException(); + } if (!transferResult.isOK()) { LogHelper.log(new ProvisionException(transferResult)); return null; @@ -718,8 +766,9 @@ private BundleDescription parseBundleDescription(URI bundleURI, IProgressMonitor } catch (IOException e) { LogHelper.log(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.ErrorReadingBundle, bundleURI), e)); } finally { - if (bundleFile != null) + if (bundleFile != null) { bundleFile.delete(); + } } return null; } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSitePublisherApplication.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSitePublisherApplication.java index afd73f1a62..bb630aff2f 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSitePublisherApplication.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/UpdateSitePublisherApplication.java @@ -43,11 +43,13 @@ public UpdateSitePublisherApplication(IProvisioningAgent agent) { protected void processParameter(String arg, String parameter, PublisherInfo pinfo) throws URISyntaxException { super.processParameter(arg, parameter, pinfo); - if (arg.equalsIgnoreCase("-categoryQualifier")) //$NON-NLS-1$ + if (arg.equalsIgnoreCase("-categoryQualifier")) { //$NON-NLS-1$ categoryQualifier = parameter; + } - if (arg.equalsIgnoreCase("-categoryVersion")) //$NON-NLS-1$ + if (arg.equalsIgnoreCase("-categoryVersion")) { //$NON-NLS-1$ categoryVersion = parameter; + } } @Override diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/VersionSuffixGenerator.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/VersionSuffixGenerator.java index 9c13469c49..e5ac96dbf0 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/VersionSuffixGenerator.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/VersionSuffixGenerator.java @@ -35,8 +35,9 @@ public static String incrementQualifier(String qualifier) { for (; idx >= 0; idx--) { //finding last non-'z' character - if (qualifier.charAt(idx) != 'z') + if (qualifier.charAt(idx) != 'z') { break; + } } if (idx >= 0) { @@ -80,18 +81,20 @@ private static int computeNameSum(String name) { int lshift = 20; for (int idx = 0; idx < top; ++idx) { int c = name.charAt(idx) & 0xffff; - if (c == '.' && lshift > 0) + if (c == '.' && lshift > 0) { lshift -= 4; - else + } else { sum += c << lshift; + } } return sum; } private static int getIntSegment(Version v, int segment) { int segCount = v.getSegmentCount(); - if (segCount <= segment) + if (segCount <= segment) { return 0; + } Object seg = v.getSegment(segment); return seg instanceof Integer ? ((Integer) seg).intValue() : 0; } @@ -110,8 +113,9 @@ private static int getMinor(Version v) { private static String getQualifier(Version v) { int segCount = v.getSegmentCount(); - if (segCount == 0) + if (segCount == 0) { return null; + } Object seg = v.getSegment(segCount - 1); return seg instanceof String ? (String) seg : null; } @@ -173,8 +177,9 @@ public VersionSuffixGenerator(int maxVersionSuffixLenght, int significantDigits) * @return The generated suffix or null */ public String generateSuffix(Collection features, Collection others) { - if (maxVersionSuffixLength <= 0 || (features.isEmpty() && others.isEmpty())) + if (maxVersionSuffixLength <= 0 || (features.isEmpty() && others.isEmpty())) { return null; // do nothing + } long majorSum = 0L; long minorSum = 0L; @@ -217,11 +222,13 @@ public String generateSuffix(Collection features, Collec if (qualifier != null && qualifier.endsWith(VERSION_QUALIFIER)) { int resultingLength = qualifier.length() - VERSION_QUALIFIER.length(); if (resultingLength > 0) { - if (qualifier.charAt(resultingLength - 1) == '.') + if (qualifier.charAt(resultingLength - 1) == '.') { resultingLength--; + } qualifier = resultingLength > 0 ? qualifier.substring(0, resultingLength) : null; - } else + } else { qualifier = null; + } } qualifiers.add(qualifier); } @@ -233,15 +240,17 @@ public String generateSuffix(Collection features, Collec int idx = qualifiers.size(); while (--idx >= 0) { String qualifier = qualifiers.get(idx); - if (qualifier == null) + if (qualifier == null) { continue; + } if (qualifier.length() > significantDigits) { qualifier = qualifier.substring(0, significantDigits); qualifiers.set(idx, qualifier); } - if (qualifier.length() > longestQualifier) + if (qualifier.length() > longestQualifier) { longestQualifier = qualifier.length(); + } } StringBuffer result = new StringBuffer(); @@ -258,12 +267,14 @@ public String generateSuffix(Collection features, Collec int top = qualifiers.size(); for (idx = 0; idx < top; ++idx) { String qualifier = qualifiers.get(idx); - if (qualifier == null) + if (qualifier == null) { continue; + } int qlen = qualifier.length(); - for (int j = 0; j < qlen; ++j) + for (int j = 0; j < qlen; ++j) { qualifierSums[j] += charValue(qualifier.charAt(j)); + } } // Normalize the sums to be base 65. @@ -278,22 +289,25 @@ public String generateSuffix(Collection features, Collec // Always use one character for overflow. This will be handled // correctly even when the overflow character itself overflows. result.append(lengthPrefixBase64(qualifierSums[0])); - for (int m = 1; m < longestQualifier; ++m) + for (int m = 1; m < longestQualifier; ++m) { appendEncodedCharacter(result, qualifierSums[m]); + } } // If the resulting suffix is too long, shorten it to the designed length. // - if (result.length() > maxVersionSuffixLength) + if (result.length() > maxVersionSuffixLength) { result.setLength(maxVersionSuffixLength); + } // It is safe to strip any '-' characters from the end of the suffix. // (This won't happen very often, but it will save us a character or // two when it does.) // int len = result.length(); - while (len > 0 && result.charAt(len - 1) == '-') + while (len > 0 && result.charAt(len - 1) == '-') { result.setLength(--len); + } return result.toString(); } } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java index 09ca1fe1f8..cb8c0abe87 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/artifact/UpdateSiteArtifactRepositoryFactory.java @@ -61,10 +61,12 @@ public IArtifactRepository load(URI location, int flags, IProgressMonitor monito initializeRepository(repository, location, monitor); } catch (Exception e) { resetCache(repository); - if (e instanceof ProvisionException) + if (e instanceof ProvisionException) { throw (ProvisionException) e; - if (e instanceof OperationCanceledException) + } + if (e instanceof OperationCanceledException) { throw (OperationCanceledException) e; + } throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Unexpected_exception, location.toString()), e)); } @@ -102,14 +104,17 @@ public void initializeRepository(IArtifactRepository repository, URI location, I throws ProvisionException { UpdateSite updateSite = UpdateSite.load(location, getAgent().getService(Transport.class), monitor); String savedChecksum = repository.getProperties().get(PROP_SITE_CHECKSUM); - if (savedChecksum != null && savedChecksum.equals(updateSite.getChecksum())) + if (savedChecksum != null && savedChecksum.equals(updateSite.getChecksum())) { return; + } - if (!location.getScheme().equals(PROTOCOL_FILE)) + if (!location.getScheme().equals(PROTOCOL_FILE)) { repository.setProperty(PROP_FORCE_THREADING, "true"); //$NON-NLS-1$ + } repository.setProperty(PROP_SITE_CHECKSUM, updateSite.getChecksum()); - if (updateSite.getSite().getMirrorsURI() != null) + if (updateSite.getSite().getMirrorsURI() != null) { repository.setProperty(IRepository.PROP_MIRRORS_URL, updateSite.getSite().getMirrorsURI()); + } repository.removeAll(new NullProgressMonitor()); generateArtifactDescriptors(updateSite, repository, monitor); } diff --git a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java index 97f805994a..e01e677552 100644 --- a/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java +++ b/bundles/org.eclipse.equinox.p2.updatesite/src/org/eclipse/equinox/internal/p2/updatesite/metadata/UpdateSiteMetadataRepositoryFactory.java @@ -66,10 +66,12 @@ public IMetadataRepository load(URI location, int flags, IProgressMonitor monito } catch (RuntimeException rte) { e.addSuppressed(rte); } - if (e instanceof ProvisionException) + if (e instanceof ProvisionException) { throw (ProvisionException) e; - if (e instanceof OperationCanceledException) + } + if (e instanceof OperationCanceledException) { throw (OperationCanceledException) e; + } throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.Unexpected_exception, location.toString()), e)); } @@ -107,18 +109,22 @@ public void initializeRepository(IMetadataRepository repository, URI location, I throws ProvisionException { UpdateSite updateSite = UpdateSite.load(location, getAgent().getService(Transport.class), monitor); String savedChecksum = repository.getProperties().get(PROP_SITE_CHECKSUM); - if (savedChecksum != null && savedChecksum.equals(updateSite.getChecksum())) + if (savedChecksum != null && savedChecksum.equals(updateSite.getChecksum())) { return; + } repository.setProperty(PROP_SITE_CHECKSUM, updateSite.getChecksum()); repository.removeAll(); IStatus status = generateMetadata(updateSite, repository, monitor); // site references should be published on load - if (repository instanceof LocalMetadataRepository) + if (repository instanceof LocalMetadataRepository) { ((LocalMetadataRepository) repository).publishRepositoryReferences(); - if (monitor.isCanceled()) + } + if (monitor.isCanceled()) { throw new OperationCanceledException(); - if (!status.isOK()) + } + if (!status.isOK()) { throw new ProvisionException(status); + } } private IStatus generateMetadata(UpdateSite updateSite, IMetadataRepository repository, IProgressMonitor monitor) {