This is an automated email from the ASF dual-hosted git repository.

pcongiusti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new fef0e61  fix(build): default jitpack to main
fef0e61 is described below

commit fef0e6174716d1b2a92b8e419fc9d41a0dc97620
Author: Pasquale Congiusti <[email protected]>
AuthorDate: Tue Nov 23 17:25:26 2021 +0100

    fix(build): default jitpack to main
    
    * Moved default from master to main
    * Added some meaningful example
    
    Closes #2764
---
 examples/README.md               |  1 +
 examples/jitpack/Jitpack.java    | 32 ++++++++++++++++++++++
 examples/jitpack/README.md       | 59 ++++++++++++++++++++++++++++++++++++++++
 pkg/util/jitpack/jitpack.go      |  9 ++++--
 pkg/util/jitpack/jitpack_test.go |  2 +-
 5 files changed, 99 insertions(+), 4 deletions(-)

diff --git a/examples/README.md b/examples/README.md
index 04b29b5..0ad9cf0 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -12,6 +12,7 @@ In this section you will find the most basic examples. Useful 
to start learning
 | Basic | Simple integrations with basic configuration | [see 
examples](./basic/)|
 | Cron | How to create a `cront` integration | [see examples](./cron/)|
 | User Config | Explore how to include a `property`, `secret`, `configmap` or 
file `resource` in your integration | [see examples](./user-config/)|
+| User Dependencies | Explore how to include a local dependency in your 
integration with Jitpack | [see examples](./jitpack/)|
 | Processor | Show how to include `Processor`s logic | [see 
examples](./processor/)|
 | Open API | `Open API` support | [see examples](./openapi/)|
 | Rest | Produce/Consume `REST`ful services | [see examples](./rest/)|
diff --git a/examples/jitpack/Jitpack.java b/examples/jitpack/Jitpack.java
new file mode 100755
index 0000000..352e603
--- /dev/null
+++ b/examples/jitpack/Jitpack.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// camel-k: language=java
+
+import org.apache.camel.builder.RouteBuilder;
+import acme.App;
+
+public class Jitpack extends RouteBuilder {
+  @Override
+  public void configure() throws Exception {
+      from("timer:tick?period=2000")
+        .setBody()
+          .simple(App.capitalize("hello"))
+        .to("log:info");
+
+  }
+}
diff --git a/examples/jitpack/README.md b/examples/jitpack/README.md
new file mode 100644
index 0000000..71aa8b4
--- /dev/null
+++ b/examples/jitpack/README.md
@@ -0,0 +1,59 @@
+# Jitpack Camel K examples
+
+Find useful examples about how to use Jitpack in a Camel K integration.
+
+## How to package a dependency
+
+Camel K supports [Jitpack](https://jitpack.io/) to allow packaging your local 
code into a running Integration. The operator will recognize the major `git` 
repositories and provide all the needed configuration to package the dependency 
and locally install into Camel K artifacts repository. As an example, we can 
use [a sample jitpack project](https://github.com/squakez/samplejp), which 
contains some developments on `main` branch, a final release tagged as `v1.0` 
and other developments ongo [...]
+
+Within your route, you can import the code as you'd normally do with any other 
library:
+
+```
+import org.apache.camel.builder.RouteBuilder;
+import acme.App;
+
+public class Jitpack extends RouteBuilder {
+  @Override
+  public void configure() throws Exception {
+      from("timer:tick?period=2000")
+        .setBody()
+          .simple(App.capitalize("hello"))
+        .to("log:info");
+
+  }
+}
+```
+
+Once done, you must just reference the project in `kamel run -d` option, ie 
`-d github:squakez/samplejp`.
+
+### Package the default branch (main)
+
+You can choose to use the default dependency without specifying a tag or 
branch, that will fetch the source code on `main` branch:
+```
+kamel run Jitpack.java --dev -d github:squakez/samplejp
+
+...
+[1] 2021-11-23 16:00:59,305 INFO  [info] (Camel (camel-1) thread #0 - 
timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: HELLO]
+...
+```
+
+### Package another branch (1.0.0)
+
+You can choose to compile the source code stored on a given branch, ie, on 
`1.0.0` branch:
+```
+kamel run Jitpack.java --dev -d github:squakez/samplejp:1.0.0-SNAPSHOT
+
+...
+[1] 2021-11-23 16:04:30,840 INFO  [info] (Camel (camel-1) thread #0 - 
timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: 
v1.0.0-SNAPSHOT:HELLO]
+...
+```
+### Package a fixed release tagged
+
+You can also choose to package the source code released with a `tag`, ie 
`v1.0`:
+```
+kamel run Jitpack.java --dev -d github:squakez/samplejp:v1.0
+
+...
+[1] 2021-11-23 16:01:49,409 INFO  [info] (Camel (camel-1) thread #0 - 
timer://tick) Exchange[ExchangePattern: InOnly, BodyType: String, Body: 
v1.0.0:HELLO]
+...
+```
diff --git a/pkg/util/jitpack/jitpack.go b/pkg/util/jitpack/jitpack.go
index 549acdf..62cd5c9 100644
--- a/pkg/util/jitpack/jitpack.go
+++ b/pkg/util/jitpack/jitpack.go
@@ -24,10 +24,13 @@ import (
 )
 
 const (
-       RepoURL       = "https://jitpack.io";
-       LatestVersion = "master-SNAPSHOT"
+       // RepoURL is the Jitpack repository url
+       RepoURL = "https://jitpack.io";
+       // DefaultVersion is the default branch/version to use
+       DefaultVersion = "main-SNAPSHOT"
 )
 
+// ToDependency converts a jitpack dependency into Dependency struct
 func ToDependency(dependencyID string) *maven.Dependency {
        gav := ""
 
@@ -62,7 +65,7 @@ func ToDependency(dependencyID string) *maven.Dependency {
        // if no version is set, then use master-SNAPSHOT which
        // targets the latest snapshot from the master branch
        if dep.Version == "" {
-               dep.Version = LatestVersion
+               dep.Version = DefaultVersion
        }
 
        return &dep
diff --git a/pkg/util/jitpack/jitpack_test.go b/pkg/util/jitpack/jitpack_test.go
index 616fe55..ada06c0 100644
--- a/pkg/util/jitpack/jitpack_test.go
+++ b/pkg/util/jitpack/jitpack_test.go
@@ -55,7 +55,7 @@ func TestConversion(t *testing.T) {
                        assert.NotNil(t, d)
                        assert.Equal(t, val.prefixGav+".u", d.GroupID)
                        assert.Equal(t, "r", d.ArtifactID)
-                       assert.Equal(t, LatestVersion, d.Version)
+                       assert.Equal(t, DefaultVersion, d.Version)
                })
        }
 }

Reply via email to