domingo, 22 de noviembre de 2020

GIT Demystifying part 5, git reset --soft HEAD~

 GIT Demystifying part 5

git reset --soft HEAD~

This command will set the HEAD on his parent, and the working directory and the Stage will have the state of the HEAD commit, with the files staged. ready to commit, or modify and commit.



After the command the files are of the commit 3, a ready to commit.


Secuence diagram of the procedure.



procedure of the 3 commits



After git reset --soft HEAD~, procedure on command line.



eot

sábado, 21 de noviembre de 2020

GIT Demystifying part 4, git reset --mixed HEAD~

GIT Demystifying part 4

git reset --mixed HEAD~ 

This command will set the HEAD on his parent, and the working directory and the Stage will have the state of the HEAD commit, with the files unstaged. ready to add and commit, or modify and commit.




After git reset --mixed HEAD~ the files will be unstaged.


Secuence diagram of the operation.

Procedure of 3 commits on command line



Procedure on Command line.


The status of the file1 will be unstaged.


We have the option to restore the file, to his previos state, file1:v2.


eot

viernes, 20 de noviembre de 2020

GIT Demystifying part 3, git reset --hard HEAD~

 GIT Demystifying part 3

git reset --hard HEAD~


This command return the head to the parent commit, and the state will be of the parent commit.


State is on commit 3.


when apply git reset --hard Head~, head points to his parent, and the state will be updated, the previos state will be lost.



Secuence diagram of operations


initial 3 commits command line


Procedure on command line



eot

jueves, 19 de noviembre de 2020

GIT Demystifying part 2

 GIT Demystifying part 2

 The file1 is modified by user and marked as red because it need to be added in order to be able to commit it, the user undo the changes and disappear of the Stage area. The same undo operation can be achieved simply by the git restore file1 command.

Also can see the diference between git rm and simply rm command.




  Detailed operations on console, for modify file1, create file2, add and commit


Detailed operations on console, for Delete File2 from Working Directory and in Stage ready to Commit
and Delete File1 from Working Directory, Stage.


Actually there no are file1 or file2 on Working Directory. The file can be restored with
git restore file1
or commited with
git commit -a -m "file1 deleted"

At this point we have file2 deleted commited, and file1 deleted from Working Directory.
what we can do with file1.

1.- Restore file1, I mean undelete it, with git restore file1 command.
2.- prepare to commit his delete of file1. with git add file1 command.

eot

miércoles, 18 de noviembre de 2020

GIT Demystifying part 1

 GIT demystifying part 1


  This Diagram shows the basic different git commands to change the state of the files.


References: https://git-scm.com/

Requirements: Git installed

  This Lab demystify by example what happen when git commands are applied. Start with basic commands and see the efects of this command over the different states of Git, this are the Working Directory, the Stage or index, and the History or the Commits.

On this particular case, we use a directory created by an Ide (IntelliJ), so this directory has some files and directories that are not relevant to be considered over the development of this lab, so we use the .gitfile ignore to add this exclusions. simply after create de project with the ide, in the main directory of the project we create the .gitignore file with the next content that can be modified accord to our needs.

file .gitignore :
.gitignore
.idea
.iml
src/

this will leave the git status info clean of files that don´t want to be treated on this lab. Also config the git with personal info, this must be personal accord to each one. this is the name and email that is registered along the commits history.

Config Git

  Open file explorer and select the directory of work, right click over it -> Git bash Here, on this console type the git commands: 

git config --global user.name "jalbertomr"
git config --global user.email "jalbertomr@yahoo.com"
git config --list

1.- Work with file1 create, add and commit

  We will work with one file, first our directory has some native files that own to the project and ignored thanks to .gitignore file.

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/gitLab01 (master)
$ ls -a
./  ../  .git/  .gitignore  .idea/  gitLab01.iml  src/

This is a very simple case where create a file1 is added to Stage and Commited.

In Detail the same commands with console response, and showing the result of
git status 
git diff                   : shows the difference between Working Dir and Stage. 
git diff --staged     : shows the difference between Stage and History.

check the color of the unatached file1 in orange and the same file attached by add command change to green. and finally with git log the commit appears.


2.- Work with file2 create, move it from Working Dir to Stage, from Stage to Working Dir and delete it, and never commited.

   Lets create file2 then add it, once staged, return it to unstaged condition to finally remove it, so never commited.


Detailed operacions in console

  The important here is to see that once the file is in Stage, the command git diff --stage, report de diference between Stage and History.


eot

viernes, 2 de octubre de 2020

STS4 Java version Maven Simple Configuration

 STS4 Java version Maven Simple Configuration



1 .- Create a New Maven Project
    




2.- Create a java program for java 8

By default the JRE System Library y set to J2SE-1.5, and the code complains because this is not compatible, so in the pom we can specify the java version. 



One modified the pom, update the pom, the result is the JRE System Library node change to JavaSE-1.8, and the code stop complain.


Now test the code selecting the class and run as application.


From terminal (Windows -> Show View -> Terminal -> click on icon open terminal
and type mvn clean compile.


Now, modify the pom to specify the output to jar file, and the details for Manifest.

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.maven.lab</groupId>
<artifactId>mavenjavaversion</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>

<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.maven.lab.MavenJavaVersion</mainClass>
</manifest>
</archive>
</configuration>

</plugin>
</plugins>
</build>
</project> 

From Terminal type mvn clean compile.

$ mvn clean compile
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.maven.lab:mavenjavaversion:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 18, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -------------------< com.maven.lab:mavenjavaversion >-------------------
[INFO] Building mavenjavaversion 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mavenjavaversion ---
[INFO] Deleting C:\Users\bext\Documents\workspaceSTS448\mavenjavaversion\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mavenjavaversion ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mavenjavaversion ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform

And mvn install

$ mvn install
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.maven.lab:mavenjavaversion:jar:0.0.1-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 18, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] -------------------< com.maven.lab:mavenjavaversion >-------------------
[INFO] Building mavenjavaversion 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ mavenjavaversion ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ mavenjavaversion ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ mavenjavaversion ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ mavenjavaversion ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ mavenjavaversion ---
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ mavenjavaversion ---
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mavenjavaversion ---
[INFO] Installing C:\Users\bext\Documents\workspaceSTS448\mavenjavaversion\target\mavenjavaversion-0.0.1-SNAPSHOT.jar to C:\Users\bext\.m2\repository\com\maven\lab\mavenjavaversion\0.0.1-SNAPS
[INFO] Installing C:\Users\bext\Documents\workspaceSTS448\mavenjavaversion\pom.xml to C:\Users\bext\.m2\repository\com\maven\lab\mavenjavaversion\0.0.1-SNAPSHOT\mavenjavaversion-0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.891 s
[INFO] Finished at: 2020-10-02T22:33:21-05:00
[INFO] ------------------------------------------------------------------------

And Run it from the Terminal
$ cd target

bext@DESKTOP-NLF0058 MINGW64 ~/Documents/workspaceSTS448/mavenjavaversion/target
$ java -jar mavenjavaversion-0.0.1-SNAPSHOT.jar
aaa1
abc1



eot

martes, 29 de septiembre de 2020

Java IntelliJ Simple Gradle Project

 Java IntelliJ Simple Gradle Project



                                                                                                              reference IntelliJ web page.

https://github.com/jalbertomr/simpleGradleProject

Steps to follow

1 .- Create a Simple Gradle Project. with Junit.

2 .- Add Simple Java Code, and Tests.

3 .-  Run application with Gradle.

4 .- Run Tests

5 .- Create Executable JAR file

6 .- Run the JAR file with Gradle.


1 .- Create a Simple Gradle Project. with Junit.

.Create a New Project of type Gradle with Java.


Assign a GroupId and ArtifactId.


Assign a Project name.


In the Project window, the structure of de project is like shows on figure below, the file build.gradle put by default some instructions. like plugins, repositories, dependencies. the external libraries correspond with the dependencies in build.gradle file. this is automatically done.


 Open the Gradle window. View -> Tools Window -> Gradle. On the folders of Gradle view the task shows the task we can run.


Also we can adjust some other characteristics of our Gradle project in Project Settings, Build, Execution, Deployment ->Build Tools -> Gradle.


Project Structure (Ctl+Alt+Shift+S)


2 .- Add Simple Java Code, and Tests.

Add simple Java Code
package com.gradle.tutorial;

public class NumberProcessor {
public static void main(String[] args) {
for (int i = 1; i < 100; i++){
System.out.println( convert(i));
}
}

public static String convert(int numberProcessor) {
if ( numberProcessor % 15 == 0) {
return "tresYcinco";
}
if ( numberProcessor % 3 == 0) {
return "tres";
}
if ( numberProcessor % 5 == 0) {
return "cinco";
}
return String.valueOf(numberProcessor);
}
}

Create his Test class

Put the cursor over class NumberProcessor and then type Ctrl+Shift+T, and code the test.

package com.gradle.tutorial;

import org.junit.Assert;
import org.junit.Test;

public class NumberProcessorTest {
@Test
public void NumberNormalNumbers() {
NumberProcessor np = new NumberProcessor();
Assert.assertEquals("1", np.convert(1));
Assert.assertEquals("2", np.convert(2));
}

@Test
public void NumberTres() {
NumberProcessor np = new NumberProcessor();
Assert.assertEquals("tres", np.convert(3));
}

@Test
public void NumberCinco() {
NumberProcessor np = new NumberProcessor();
Assert.assertEquals("cinco", np.convert(5));
}

@Test
public void NumberTresYCinco(){
NumberProcessor np = new NumberProcessor();
Assert.assertEquals("tresYcinco", np.convert(15));
}

}

3 .-  Run application with Gradle.


The output
11:31:16 a. m.: Executing task 'NumberProcessor.main()'...
> Task :compileJava
> Task :processResources NO-SOURCE
> Task :classes
> Task :NumberProcessor.main()
1
2
tres
4
cinco
tres
7
8
tres
cinco
11
tres
13
14
tresYcinco
Ok, the program works.

4 .- Run Tests

On the file of Test NumberProcessorTest.java, we can run individual test, putting the cursor over the function test and run the test.


The output of the Test is OK.


Now lets alter the Test to get a Fail output, just to see.

5 .- Create Executable JAR file

In the Gradle Tool Window, in the Tasks node, and select build task to run it.


Once build the project, in the project window is generated the jar file on build -> libs


Run the program with java -jar

D:\proy\simpleGradleProject>java -jar build\libs\gradle-1.0-SNAPSHOT.jarno main manifest attribute, in build\libs\gradle-1.0-SNAPSHOT.jar

We get an error, about main manifest attribute, we have to adjust the gradle file. and add the folowing lines.

jar {
manifest {
attributes "Main-Class": "com.gradle.tutorial.NumberProcessor"
}
from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
}
}

Rebuid the project and run it again.

D:\proy\simpleGradleProject>java -jar build\libs\gradle-1.0-SNAPSHOT.jar
1
2
tres
4
cinco

6 .- Run the JAR file with Gradle.

Add the following lines to the gradle.file

plugins {
id 'java'
id 'application'
}

and

application {
mainClassName = 'com.gradle.tutorial.NumberProcessor'
}

It creates in Gradle Tool windows the node Task -> application -> run. 

and in the Project Window creates build -> distribution node.


And its done.

eot