Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
essiembre committed Aug 25, 2016
2 parents 36b921b + 364c471 commit e83bd9f
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 15 deletions.
14 changes: 12 additions & 2 deletions norconex-commons-lang/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.norconex.commons</groupId>
<artifactId>norconex-commons-lang</artifactId>
<version>1.10.0</version>
<version>1.11.0</version>
<packaging>jar</packaging>
<name>Norconex Commons Lang</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<site.baseurl/>
<currentStableVersion>1.10.0</currentStableVersion>
<currentStableVersion>1.11.0</currentStableVersion>
</properties>
<inceptionYear>2008</inceptionYear>

Expand Down Expand Up @@ -96,6 +96,16 @@
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<resources>
<resource>
Expand Down
15 changes: 14 additions & 1 deletion norconex-commons-lang/src/changes/changes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,20 @@
</properties>
<body>

<release version="1.10.0-SNAPSHOT" date="2016-??-??" description="Feature release">
<release version="1.11.0" date="2016-08-25" description="Feature release">
<action dev="essiembre" type="add">
New URLNormalizer#removeTrailingSlash() method.
</action>
<action dev="essiembre" type="update">
URLNormalizer#addTrailingSlash() has been deprecated in favor
of URLNormalizer#addDirectoryTrailingSlash().
</action>
<action dev="essiembre" type="update">
Dependency updates: Apache Commons Lang 2.6.
</action>
</release>

<release version="1.10.0" date="2016-08-22" description="Feature release">
<action dev="essiembre" type="add">
New Jar-related utility classes for jar file version conflict detection
and resolution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ private int getDuplicatesHandlingUserGlobalChoice() {
info("How do you want to handle duplicates? For each Jar...");
info("");
info(" 1) Copy source Jar only if greater or same version as target");
info(" Jar after renaming target Jar (.bak-[timestamp]).");
info(" Jar after renaming target Jar (preferred option).");
info("");
info(" 2) Copy source Jar only if greater or same version as target");
info(" Jar after deleting target Jar.");
Expand Down Expand Up @@ -340,8 +340,7 @@ private int getDuplicatesHandlingUserFileChoice() {
info("");
info("Your action:");
info("");
info(" 1) Copy source Jar after renaming target Jar "
+ "(.bak-[timestamp]).");
info(" 1) Copy source Jar after renaming target Jar.");
info("");
info(" 2) Copy source Jar after deleting target Jar.");
info("");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ public URLNormalizer removeDefaultPort() {
}
return this;
}

/**
* <p>Adds a trailing slash (/) to a URL ending with a directory. A URL is
* considered to end with a directory if the last path segment,
Expand All @@ -323,8 +324,9 @@ public URLNormalizer removeDefaultPort() {
* <code>http://www.example.com/alice &rarr;
* http://www.example.com/alice/</code>
* @return this instance
* @since 1.11.0 (renamed from "addTrailingSlash")
*/
public URLNormalizer addTrailingSlash() {
public URLNormalizer addDirectoryTrailingSlash() {
String urlRoot = HttpURL.getRoot(url);
String path = toURL().getPath();
String urlRootAndPath = urlRoot + path;
Expand All @@ -337,7 +339,53 @@ public URLNormalizer addTrailingSlash() {
url, urlRootAndPath, newUrlRootAndPath);
}
return this;
}
}

/**
* <p>Adds a trailing slash (/) to a URL ending with a directory. A URL is
* considered to end with a directory if the last path segment,
* before fragment (#) or query string (?), does not contain a dot,
* typically representing an extension.</p>
*
* <p><b>Please Note:</b> URLs do not always denote a directory structure
* and many URLs can qualify to this method without truly representing a
* directory. Adding a trailing slash to these URLs could potentially break
* its semantic equivalence.</p>
* <code>http://www.example.com/alice &rarr;
* http://www.example.com/alice/</code>
* @return this instance
* @deprecated Since 1.11.0, use {@link #addDirectoryTrailingSlash()}
*/
@Deprecated
public URLNormalizer addTrailingSlash() {
return addDirectoryTrailingSlash();
}

/**
* <p>Removes any trailing slash (/) from a URL, before fragment
* (#) or query string (?).</p>
*
* <p><b>Please Note:</b> Removing trailing slashes form URLs
* could potentially break their semantic equivalence.</p>
* <code>http://www.example.com/alice/ &rarr;
* http://www.example.com/alice</code>
* @return this instance
* @since 1.11.0
*/
public URLNormalizer removeTrailingSlash() {
String urlRoot = HttpURL.getRoot(url);
String path = toURL().getPath();
String urlRootAndPath = urlRoot + path;

if (StringUtils.endsWith(path, "/")) {
String newPath = StringUtils.removeEnd(path, "/");
String newUrlRootAndPath = urlRoot + newPath;
url = StringUtils.replaceOnce(
url, urlRootAndPath, newUrlRootAndPath);
}
return this;
}


/**
* <p>Removes the unnecessary "." and ".." segments from the URL path.
Expand Down
2 changes: 2 additions & 0 deletions norconex-commons-lang/src/site/markdown/download.md.vm
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ $h2 Binaries

**Older Releases**

* [1.10.0]($nexusPath/1.10.0/norconex-commons-lang-1.10.0.zip)<small>
[[Release Notes](changes-report.html#a1.10.0)]</small>
* [1.9.1]($nexusPath/1.9.1/norconex-commons-lang-1.9.1.zip)<small>
[[Release Notes](changes-report.html#a1.9.1)]</small>
* [1.9.0]($nexusPath/1.9.0/norconex-commons-lang-1.9.0.zip)<small>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void testAllAtOnce() {
//System.out.println("original : " + s);

URLNormalizer n = new URLNormalizer(s)
.addTrailingSlash()
.addDirectoryTrailingSlash()
.addWWW()
.removeFragment()
.decodeUnreservedCharacters()
Expand Down Expand Up @@ -163,24 +163,53 @@ public void testRemoveDefaultPort() {
public void testAddTrailingSlash() {
s = "http://www.example.com/alice";
t = "http://www.example.com/alice/";
assertEquals(t, n(s).addTrailingSlash().toString());
assertEquals(t, n(s).addDirectoryTrailingSlash().toString());
s = "http://www.example.com/alice.html";
t = "http://www.example.com/alice.html";
assertEquals(t, n(s).addTrailingSlash().toString());
assertEquals(t, n(s).addDirectoryTrailingSlash().toString());
s = "http://www.example.com";
t = "http://www.example.com";
assertEquals(t, n(s).addTrailingSlash().toString());
assertEquals(t, n(s).addDirectoryTrailingSlash().toString());
s = "http://www.example.com/blah/?param=value";
t = "http://www.example.com/blah/?param=value";
assertEquals(t, n(s).addTrailingSlash().toString());
assertEquals(t, n(s).addDirectoryTrailingSlash().toString());
s = "http://www.example.com/blah?param=value";
t = "http://www.example.com/blah/?param=value";
assertEquals(t, n(s).addTrailingSlash().toString());
assertEquals(t, n(s).addDirectoryTrailingSlash().toString());
// This one is for HTTP Collector GitHub issue #163:
s = "http://www.example.com/";
t = "http://www.example.com/";
assertEquals(t, n(s).addTrailingSlash().toString());
assertEquals(t, n(s).addDirectoryTrailingSlash().toString());
}

@Test
public void testRemoveTrailingSlash() {
s = "http://www.example.com/alice/";
t = "http://www.example.com/alice";
assertEquals(t, n(s).removeTrailingSlash().toString());
s = "http://www.example.com/alice.html";
t = "http://www.example.com/alice.html";
assertEquals(t, n(s).removeTrailingSlash().toString());
s = "http://www.example.com";
t = "http://www.example.com";
assertEquals(t, n(s).removeTrailingSlash().toString());
s = "http://www.example.com/blah/?param=value";
t = "http://www.example.com/blah?param=value";
assertEquals(t, n(s).removeTrailingSlash().toString());
s = "http://www.example.com/blah?param=value";
t = "http://www.example.com/blah?param=value";
assertEquals(t, n(s).removeTrailingSlash().toString());
s = "http://www.example.com/blah/#value";
t = "http://www.example.com/blah#value";
assertEquals(t, n(s).removeTrailingSlash().toString());
s = "http://www.example.com/blah#value";
t = "http://www.example.com/blah#value";
assertEquals(t, n(s).removeTrailingSlash().toString());
s = "http://www.example.com/";
t = "http://www.example.com";
assertEquals(t, n(s).removeTrailingSlash().toString());
}

@Test
public void testRemoveDotSegments() {
s = "http://www.example.com/../a/b/../c/./d.html";
Expand Down

0 comments on commit e83bd9f

Please sign in to comment.